Click here to Skip to main content
15,887,822 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
In asp.net web application while uploading image, sometimes it save as upside down. So how to detect whether or not image is correct in asp.net c#..??
 
Some suggestion I have as, I can detect that from EXIF data related to image detail. How can I solve this issue..??
 
Please provide c# code if possible..!
 
Thank...!
Posted
Comments
Afzaal Ahmad Zeeshan 5-Sep-15 9:08am    
To check it you will need to compare it with another image that is in actual side up. Do you have that?

If not, then you cannot. And guessing might cause a problem where program will return false for images that are not upside down and so on. Also, does it really matter? What are you using as the image processing library?
[no name] 5-Sep-15 9:09am    
"sometimes it save as upside down": On what criterion you decide this?
F-ES Sitecore 5-Sep-15 10:09am    
You're not going to be able to work out if the image is upside down, you'll just have to rely on human intervention to check the images are ok, either a manual moderation workflow or just notify someone an image has been uploaded and have them look at it.

1 solution

You can try the following code. It might work if your images contain the EXIF orientation value.
It is easy enough to test the code below and see if the property ID exist.
Not sure this will solve your problem, but it is worth a try.

C#
Image img = Image.FromFile("some file path");
if (img.PropertyIdList.Contains(0x0112))
{
    PropertyItem propOrientation = _image.GetPropertyItem(0x0112);
    short orientation = BitConverter.ToInt16(propOrientation.Value, 0);
    if (orientation == 6)
    {
        img.RotateFlip(RotateFlipType.Rotate90FlipNone);
    }
    else if (orientation == 8)
    {
        img.RotateFlip(RotateFlipType.Rotate270FlipNone);
    }
    else
    {
        // Do nothing
    }
}


Orientation Values
1 = Horizontal
6 = Vertical, rotated 90 degrees
8 = Vertical, rotated 270 degrees

The above values works at least on pictures taken with my Canon DSLR camera.
I have never tried to take a picture upside down, though.
 
Share this answer
 
v3
Comments
[no name] 6-Sep-15 6:18am    
Cool, thank you for that and have a 5.
Kailas_ 7-Sep-15 2:19am    
Even it not contain 0x0112..
George Jonsson 7-Sep-15 3:31am    
If your image doesn't contain the orientation property (0x0112), the code above will not work. Images created by a camera should have the property, but images created in Photoshop or similar software will probably not have it.
There might be a possibility to use a vision library, such as OpenCV, to do some clever analysis of the image, but this is beyond my knowledge.
I also assume that it will be difficult to get a fool proof solution.
Kailas_ 7-Sep-15 5:16am    
I have used ExifLib for getting image related detail but still not working..
Kailas_ 8-Sep-15 1:34am    
Hey friend thanks for suggestion above code helpful but I got true issue and that is only happen with image if it is taken by iphone..
Once again thanks Mr. George Jonsson.. :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900