Readdy Write  
0,00 €
Your View Money
Views: Count
Self 20% 0
Your Content 60% 0

Users by Links 0
u1*(Content+Views) 10% 0
Follow-Follower 0
s2*(Income) 5% 0

Count
Followers 0
Login Register as User

Fotos vom Smartphone automatisch drehen

05.05.2018 (👁3549)


 

Wenn man Fotos vom Smartphone auf eine Webseite hochlädt, dann werden diese falsch angezeigt.

Denn Fotos werden vom Smartphone mit dem Rotationswinkel gespeichert.

Deshalb muss man ein Foto beim Import automatisch drehen.

 

Hierzu muss man aus dem Upload File ein Image (Bitmap) bilden und anschliessend die Properties 0x0112 abfragen

Image.GetPropertyItem(0x0112).Value[0];

 

Anschliessend kann man das Bild drehen

originalImage.RotateFlip(rotateFlipType: RotateFlipType.Rotate90FlipNone);

 

Asp.Net Core 2 MVC

 

//----< check Properties >----

Image originalImage = Image.FromFile(new_FullFilename_on_Server);

if (originalImage.PropertyIdList.Contains(0x0112))

{

    int rotationValue = originalImage.GetPropertyItem(0x0112).Value[0];

    switch (rotationValue)

    {

        case 1: // landscape, do nothing

            break;

 

        case 8: // rotated 90 right

                // de-rotate:

            originalImage.RotateFlip(rotateFlipType: RotateFlipType.Rotate270FlipNone);

            originalImage.Save(new_FullFilename_on_Server);

            break;

 

        case 3: // bottoms up

            originalImage.RotateFlip(rotateFlipType: RotateFlipType.Rotate180FlipNone);

            originalImage.Save(new_FullFilename_on_Server);

            break;

 

        case 6: // rotated 90 left

            originalImage.RotateFlip(rotateFlipType: RotateFlipType.Rotate90FlipNone);

            originalImage.Save(new_FullFilename_on_Server);

            break;

    }       

}

originalImage.Dispose();

//----</ check Properties >----

 

 

Referenz: Code von CodeProject