後來想到有一個名詞上網找了一下
可交換圖檔格式常被簡稱為Exif(Exchangeable image file format)
裡面有個選項是圖像方向於是找了發現非標準
想說是否能抓取EXif取得圖片轉的方向然後將圖片轉回來
很幸運的網路已經有人寫過將之修改
if (file != null && file.Count() > 0) { foreach (var item in file) { if (item != null) { //轉成圖片 System.Drawing.Image img = System.Drawing.Image.FromStream(item.InputStream); //取得旋轉度數 foreach (var prop in img.PropertyItems) { if (prop.Id == 0x0112) //value of EXIF { int orientationValue = img.GetPropertyItem(prop.Id).Value[0]; RotateFlipType rotateFlipType = GetOrientationToFlipType(orientationValue);//取得轉的度數 img.RotateFlip(rotateFlipType);//依度數轉成正的 break; } } //處理圖片 轉二進位 或存到路徑上 //byte[] byteImage = imageToByteArray(img);//轉二進位 //img.Save..... } } } public static RotateFlipType GetOrientationToFlipType(int orientationValue) { RotateFlipType rotateFlipType = RotateFlipType.RotateNoneFlipNone; switch (orientationValue) { case 1: rotateFlipType = RotateFlipType.RotateNoneFlipNone; break; case 2: rotateFlipType = RotateFlipType.RotateNoneFlipX; break; case 3: rotateFlipType = RotateFlipType.Rotate180FlipNone; break; case 4: rotateFlipType = RotateFlipType.Rotate180FlipX; break; case 5: rotateFlipType = RotateFlipType.Rotate90FlipX; break; case 6: rotateFlipType = RotateFlipType.Rotate90FlipNone; break; case 7: rotateFlipType = RotateFlipType.Rotate270FlipX; break; case 8: rotateFlipType = RotateFlipType.Rotate270FlipNone; break; default: rotateFlipType = RotateFlipType.RotateNoneFlipNone; break; } return rotateFlipType; }參考來源
EXIF
Reset Image Orientation using EXIF in C#