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

Automatically rotate photos from the smartphone

05.05.2018 (👁3324)


 

If you upload photos from your smartphone to a web page, they will be displayed incorrectly.

Because photos are stored by the smartphone with the rotation angle.

Therefore you have to rotate a photo automatically when importing.

 

To do this, you have to create an image (bitmap) from the upload file and then query the properties 0x0112

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

 

Then you can rotate the picture

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 >----

 

 

Reference: Code from CodeProject