Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在vb.net中纠正服务器端的图像方向_Vb.net_Image_Orientation_Exif - Fatal编程技术网

在vb.net中纠正服务器端的图像方向

在vb.net中纠正服务器端的图像方向,vb.net,image,orientation,exif,Vb.net,Image,Orientation,Exif,在我正在开发的一个移动web应用程序中,允许用户使用相机拍照,并将相机图像上传到服务器。我遇到的问题是,在iOS设备上,图像会得到一个与之相关联的EXIF方向标记,如“旋转90 CW”。此方向标记会导致图像在显示时以不正确的方向显示。例如,如果用户用iPhone纵向拍摄某物,则在服务器上查看时,图像似乎会旋转到横向。我想使用VB.Net在服务器端更正此问题,以便自动检测EXIF方向标记,如果它是“旋转90 CW”(或任何其他会使图像显示不正确的值),则我想自动将图像旋转到正确的方向。总之,我希望

在我正在开发的一个移动web应用程序中,允许用户使用相机拍照,并将相机图像上传到服务器。我遇到的问题是,在iOS设备上,图像会得到一个与之相关联的EXIF方向标记,如“旋转90 CW”。此方向标记会导致图像在显示时以不正确的方向显示。例如,如果用户用iPhone纵向拍摄某物,则在服务器上查看时,图像似乎会旋转到横向。我想使用VB.Net在服务器端更正此问题,以便自动检测EXIF方向标记,如果它是“旋转90 CW”(或任何其他会使图像显示不正确的值),则我想自动将图像旋转到正确的方向。总之,我希望服务器上的图像与用户使用相机拍照时的图像完全相同


有人可以发布代码来实现这一点吗?提前感谢。

对于任何需要此功能的人,我基本上在VB.Net中使用此代码解决了此问题。我发现这正是我所需要的:

  Public Function TestRotate(sImageFilePath As String) As Boolean
    Dim rft As RotateFlipType = RotateFlipType.RotateNoneFlipNone
    Dim img As Bitmap = Image.FromFile(sImageFilePath)
    Dim properties As PropertyItem() = img.PropertyItems
    Dim bReturn As Boolean = False
    For Each p As PropertyItem In properties
      If p.Id = 274 Then
        Dim orientation As Short = BitConverter.ToInt16(p.Value, 0)
        Select Case orientation
          Case 1
            rft = RotateFlipType.RotateNoneFlipNone
          Case 3
            rft = RotateFlipType.Rotate180FlipNone
          Case 6
           rft = RotateFlipType.Rotate90FlipNone
          Case 8
           rft = RotateFlipType.Rotate270FlipNone
        End Select
      End If
    Next
    If rft <> RotateFlipType.RotateNoneFlipNone Then
      img.RotateFlip(rft)
      System.IO.File.Delete(sImageFilePath)
      img.Save(sImageFilePath, System.Drawing.Imaging.ImageFormat.Jpeg)
      bReturn = True
    End If
    Return bReturn

  End Function
公共函数TestRotate(sImageFilePath作为字符串)作为布尔值
尺寸rft为RotateFlipType=RotateFlipType.RotateNoneFlipNone
将img调整为位图=Image.FromFile(sImageFilePath)
将属性标注为PropertyItem()=img.PropertyItems
Dim bReturn为布尔值=False
对于属性中的每个p As PropertyItem
如果p.Id=274,则
尺寸方向为短=位转换器.ToInt16(p.值,0)
选择案例方向
案例1
rft=RotateFlipType.RotateNoneFlipNone
案例3
rft=RotateFlipType.Rotate180FlipNone
案例6
rft=RotateFlipType.Rotate90FlipNone
案例8
rft=RotateFlipType.Rotate270FlipNone
结束选择
如果结束
下一个
如果rft RotateFlipType.RotateNoneFlipNone,则
旋转唇模(rft)
System.IO.File.Delete(sImageFilePath)
保存(sImageFilePath,System.Drawing.Imaging.ImageFormat.Jpeg)
bReturn=True
如果结束
回程回程
端函数
对于任何感兴趣的人。。。C版本


你是在要求一个可以拍摄图像并旋转的代码,比如说旋转90??是的。服务器端的图像是JPEG文件的形式,因此我想打开JPEG文件,旋转其中的图像,然后使用相同的文件名将旋转后的图像写回JPEG文件。这是最基本的操作,但除此之外,我正在寻找VB.NET4.5中的一种算法,该算法可以自动更正使用EXIF方向标记找到的任何JPEG图像,如上面所示。我一直在尝试写这篇文章,但到目前为止失败了。NET没有EXIF支持,因此您必须使用其中一个库来读取该部分的EXIF数据。其余的,旋转位图是非常直接的,并且是.NET自带的。这对我有很大帮助。谢谢
public static bool TestRotate(string filePath)
{
    var rft = RotateFlipType.RotateNoneFlipNone;
    var img = Image.FromFile(filePath);
    var properties = img.PropertyItems;
    var value = false;

    foreach (var prop in properties.Where(i => i.Id == 274))
    {
        var orientation = BitConverter.ToInt16(prop.Value, 0);
        rft = orientation == 1 ? RotateFlipType.RotateNoneFlipNone :
                orientation == 3 ? RotateFlipType.Rotate180FlipNone :
                orientation == 6 ? RotateFlipType.Rotate90FlipNone :
                orientation == 8 ? RotateFlipType.Rotate270FlipNone :
                RotateFlipType.RotateNoneFlipNone;
    }

    if (rft != RotateFlipType.RotateNoneFlipNone)
    {
        img.RotateFlip(rft);
        File.Delete(filePath);
        img.Save(filePath, ImageFormat.Jpeg);
        value = true;
    }

    return value;
}