如何更改图像文件旋转状态而不将其加载到内存中
有人告诉我像 jpg 这样的图像文件只是使用一些位来控制旋转状态。
有没有办法在不将图片文件加载到主内存的情况下更改此状态
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 picture file to main memory
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可以标记 JPG 文件以更改其显示方式,而无需将 JPG 图像加载并解码为内存中的位图。 JPG 图像文件可以选择包含 EXIF 元数据部分,通常用于描述创建或捕获图像所涉及的设备和环境 - 相机型号、快门速度、ISO 曝光等效值等。EXIF
元数据还包含方向标志它可用于通知图像查看器应用程序 JPG 图像的像素应如何在显示表面上定向。该方向标志(和 EXIF 元数据)可以在 JPG 文件中读取和写入,而无需加载或解码像素图像数据。这也意味着可以多次更改方向而不会丢失图像细节,因为图像不会被解压缩、旋转,然后重新压缩到磁盘上的新文件中。
为此,您需要 C# 代码来读取 JPG 文件的 JFIF 文件格式并查找并提取 EXIF 部分。我认为内置的 .NET 图像阅读器没有提供类似的功能。
请注意,并非所有 JPG 阅读器都遵循 EXIF 方向标志。我相信 Windows 内置图像预览应用程序在当前版本的 Windows 中尊重 EXIF 方向标志,但在早期的 Windows 版本(例如 Windows XP)中则不然。
有关 EXIF 方向标志的更多信息,请访问:http://jpegclub.org/exif_orientation.html
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