RPM*_*984 51 c# jpeg metadata gdi image-processing
我有一张在iphone上拍摄的JPEG图像.在我的台式PC(Windows照片查看器,谷歌浏览器等)上,方向不正确.
我正在开发一个ASP.NET MVC 3 Web应用程序,我需要上传照片(目前正在使用plupload).
我有一些服务器端代码来处理图像,包括读取EXIF数据.
我已经尝试PropertyTagOrientation在EXIF元数据中读取字段(使用GDI - Image.PropertyItems),但该字段不存在.
所以它是一些特定的iphone元数据,或者其他一些元数据.
我使用了另一种工具,如Aurigma Photo Uploader,它正确读取元数据并旋转图像.它是如何做到的?
有没有人知道其他JPEG元数据可以包含所需的信息,以便知道它需要旋转,Aurigma使用的是什么?
这是我用来读取EXIF数据的代码:
var image = Image.FromStream(fileStream);
foreach (var prop in image.PropertyItems)
{
if (prop.Id == 112 || prop.Id == 5029)
{
// do my rotate code - e.g "RotateFlip"
// Never get's in here - can't find these properties.
}
}
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
Ree*_*gnE 118
EXIF ID 0x0112用于Orientation.这是一个有用的EXIF ID参考http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/EXIF.html
0x0112是等效于274的十六进制.的数据类型PropertyItem.Id是int,这意味着274是什么是有用的在这里.
此外,5029有可能被认为是0x5029或20521这关联到ThumbnailOrientation,虽然可能不是这里需要的.
注意:img是一个System.Drawing.Image或继承自它,就像System.Drawing.Bitmap.
if (Array.IndexOf(img.PropertyIdList, 274) > -1)
{
var orientation = (int)img.GetPropertyItem(274).Value[0];
switch (orientation)
{
case 1:
// No rotation required.
break;
case 2:
img.RotateFlip(RotateFlipType.RotateNoneFlipX);
break;
case 3:
img.RotateFlip(RotateFlipType.Rotate180FlipNone);
break;
case 4:
img.RotateFlip(RotateFlipType.Rotate180FlipX);
break;
case 5:
img.RotateFlip(RotateFlipType.Rotate90FlipX);
break;
case 6:
img.RotateFlip(RotateFlipType.Rotate90FlipNone);
break;
case 7:
img.RotateFlip(RotateFlipType.Rotate270FlipX);
break;
case 8:
img.RotateFlip(RotateFlipType.Rotate270FlipNone);
break;
}
// This EXIF data is now invalid and should be removed.
img.RemovePropertyItem(274);
}
Run Code Online (Sandbox Code Playgroud)
Bal*_*a R 14
从这篇文章看起来你需要检查ID 274
foreach (PropertyItem p in properties) {
if (p.Id == 274) {
Orientation = (int)p.Value[0];
if (Orientation == 6)
oldImage.RotateFlip(RotateFlipType.Rotate90FlipNone);
if (Orientation == 8)
oldImage.RotateFlip(RotateFlipType.Rotate270FlipNone);
break;
}
}
Run Code Online (Sandbox Code Playgroud)
小智 11
我结合了给定的答案和评论,并提出了这个问题:
MemoryStream stream = new MemoryStream(data);
Image image = Image.FromStream(stream);
foreach (var prop in image.PropertyItems) {
if ((prop.Id == 0x0112 || prop.Id == 5029 || prop.Id == 274)) {
var value = (int)prop.Value[0];
if (value == 6) {
image.RotateFlip(RotateFlipType.Rotate90FlipNone);
break;
} else if (value == 8) {
image.RotateFlip(RotateFlipType.Rotate270FlipNone);
break;
} else if (value == 3) {
image.RotateFlip(RotateFlipType.Rotate180FlipNone);
break;
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
29857 次 |
| 最近记录: |