2016年5月3日 星期二

[C#][EXIFextractor] Mobile Web 上傳圖片,照片翻轉90度 rotateImage


遇到這種問題 有點傻眼

不知道怎麼解決,測了也沒發現什麼規律性的原因(偏偏我就是拿偏偏我就是用iphone safari)

頓時有了希望全世界都生活在智障型手機的時代是多麼美好,多麼幸福,多麼......方便 ORZ

不過感嘆歸感嘆,希望歸希望,身為21世紀現代人類,還是要追求一下科技進步、社會發展



不用你們提醒我,我知道我現在很難得的正在囉嗦.............

[問題原因] 貌似是瀏覽器吃不到照片的一些tag

這裡有針對IOS詳細介紹照片方向的問題

解決之前 還要加入參考

點我連結下載頁面  進去之後點 Donload Source files

code在這

方便大家 也為了防止頁面被404狙擊 我還是備份一下



  1. HttpPostedFile file = HttpContext.Current.Request.Files["file"];
  2. //Create bitmap image from posted file
  3. System.Drawing.Bitmap bmpImg = new System.Drawing.Bitmap(file.InputStream);
  4. //rotate if needed
  5. bmpImg = rotateImage(bmpImg);
  6. //save image
  7. targetFilePath = "somewhere...";
  8. bmpImg.Save(targetFilePath, ImageFormat.Jpeg);
  1. public Bitmap rotateImage(System.Drawing.Bitmap img)
  2. {
  3. try
  4. {
  5. RotateFlipType rft = RotateFlipType.RotateNoneFlipNone;
  6. System.Drawing.Imaging.PropertyItem[] properties = img.PropertyItems;
  7. foreach (System.Drawing.Imaging.PropertyItem p in properties)
  8. {
  9. if (p.Id == 274 || p.Id == 5029)
  10. {
  11. short orientation = BitConverter.ToInt16(p.Value, 0);
  12. switch (orientation)
  13. {
  14. case 1:
  15. rft = RotateFlipType.RotateNoneFlipNone;
  16. break;
  17. case 3:
  18. rft = RotateFlipType.Rotate180FlipNone;
  19. break;
  20. case 6:
  21. rft = RotateFlipType.Rotate90FlipNone;
  22. break;
  23. case 8:
  24. rft = RotateFlipType.Rotate270FlipNone;
  25. break;
  26. }
  27. }
  28. }
  29. if (rft != RotateFlipType.RotateNoneFlipNone)
  30. {
  31. img.RotateFlip(rft);
  32. }
  33. }
  34. catch
  35. {
  36.  
  37. }
  38. return img;
  39. }
  40.  

沒有留言:

張貼留言