如果上传图片(旋转),如何在上传图片时进行检测..? [英] How to detect while uploading image if it is upside down(rotated)..?

查看:130
本文介绍了如果上传图片(旋转),如何在上传图片时进行检测..?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在上传图片时,在asp.net网页应用程序中,有时会将其保存为颠倒。那么如何在asp.net c#中检测图像是否正确? 

我有一些建议,我可以从与图像细节相关的EXIF数据中检测出来。我怎么能解决这个问题.. ??

请尽可能提供c#代码..!

感谢...!

解决方案

您可以尝试以下代码。如果您的图片包含EXIF方向值,它可能会有效。

测试下面的代码并查看属性ID是否存在很容易。

不确定这会解决你的问题,但值得一试。



图片img = Image.FromFile( 某些文件路径); 
if (img.PropertyIdList.Contains(0x0112))
{
PropertyItem propOrientation = _image.GetPropertyItem(0x0112);
short orientation = BitConverter.ToInt16(propOrientation.Value, 0 );
if (orientation == 6
{
img。 RotateFlip(RotateFlipType.Rotate90FlipNone);
}
其他 如果(orientation == 8
{
img.RotateFlip(RotateFlipType.Rotate270FlipNone);
}
其他
{
// < span class =code-comment>什么都不做
}
}





方向值

 1 =水平
6 =垂直,旋转90度
8 =垂直,旋转270度



以上数值至少适用于使用我的佳能数码单反相机拍摄的照片。

我从未尝试过将照片颠倒过来。 / BLOCKQUOTE>

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

解决方案

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.

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.


这篇关于如果上传图片(旋转),如何在上传图片时进行检测..?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆