how to change image file rotation status without loading it into memory
Someone told me some image file like jpg just use some bits to control the rotation status.
Is there any way to change this status without loading the pictu开发者_StackOverflow中文版re file to main memory
It is possible to mark a JPG file to change how it is supposed to be displayed without loading and decoding the JPG image into an in-memory bitmap. The JPG image file can optionally include an EXIF metadata section, often used to describe the device and circumstances involved in the creation or capture of the image - Camera model, shutter speed, ISO exposure equivalent, etc.
The EXIF metadata also includes an Orientation flag which can be used to inform image viewer apps how the pixels of the JPG image should be oriented on the display surface. This orientation flag (and the EXIF metadata) can be read and written in the JPG file without loading or decoding the pixel image data. This also means that orientation can be changed multiple times without loss of image detail, since the image is not being decompressed, rotated, and then recompressed into a new file on disk.
To do this, you will need C# code that will read the JFIF file format of the JPG file and find and extract the EXIF section. I don't think the built-in .NET Image reader provides anything like that.
Note that not all JPG readers honor the EXIF orientation flag. I believe the Windows built-in Image Preview app respects the EXIF orientation flag in current versions of Windows, but it did not in earlier Windows versions such as Windows XP.
More info on the EXIF orientation flag here: http://jpegclub.org/exif_orientation.html
精彩评论