自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

使用C#旋轉(zhuǎn)圖片:EXIF

開發(fā) 后端
本文詳細(xì)介紹了C#實(shí)現(xiàn)根據(jù)圖片的EXIF自動調(diào)整圖片方向的方法,希望對大家有用。

 一、什么是EXIF

Exif是英文Exchangeable Image File(可交換圖像文件)的縮寫,最初由日本電子工業(yè)發(fā)展協(xié)會(JEIDA --Japan Electronic Industry Development Association) 制訂,目前的最新版本是發(fā)表于2002年04月的2.21 版。國際標(biāo)準(zhǔn)化組織(ISO)正在制訂的相機(jī)文件設(shè)計(jì)標(biāo)準(zhǔn)(DCF -- Design role for Camera File system)可能以Exif2.1為基礎(chǔ)。

所有的JPEG文件以字符串“0xFFD8”開頭,并以字符串“0xFFD9”結(jié)束。文件頭中有一系列“0xFF??”格式的字符串,稱為“標(biāo)識”,用來標(biāo)記JPEG文件的信息段?!?xFFD8”表示圖像信息開始,“0xFFD9”表示圖像信息結(jié)束,這兩個標(biāo)識后面沒有信息,而其它標(biāo)識緊跟一些信息字符。

0xFFE0 -- 0xFFEF之間的標(biāo)識符稱為“應(yīng)用標(biāo)記”,沒有被常規(guī)JPEG文件利用,Exif正是利用這些信息串記錄拍攝信息如快門速度、光圈值等,甚至可以包括全球定位信息。其中拍攝方向的ID為“0x0112”,有1至8共8種值。而C#旋轉(zhuǎn)圖片可以通過EXIF來實(shí)現(xiàn)。

EXIF圖1

二、EXIF Orientation

  1. Orientation   
  2. The image orientation viewed in terms of rows and columns.   
  3. Tag = 274 (112.H)   
  4. Type = SHORT   
  5. Count = 1   
  6. Default = 1   
  7. 1 = The 0th row is at the visual top of the image, and the 0th column is the visual left-hand side.   
  8. 2 = The 0th row is at the visual top of the image, and the 0th column is the visual right-hand side.   
  9. 3 = The 0th row is at the visual bottom of the image, and the 0th column is the visual right-hand side.   
  10. 4 = The 0th row is at the visual bottom of the image, and the 0th column is the visual left-hand side.   
  11. 5 = The 0th row is the visual left-hand side of the image, and the 0th column is the visual top.   
  12. 6 = The 0th row is the visual right-hand side of the image, and the 0th column is the visual top.   
  13. 7 = The 0th row is the visual right-hand side of the image, and the 0th column is the visual bottom.   
  14. 8 = The 0th row is the visual left-hand side of the image, and the 0th column is the visual bottom.   
  15. Other = reserved 

三、使用C#旋轉(zhuǎn)圖片

  1. public static void rotating(Bitmap img,ref int width, ref int height, int orien)  
  2. {  
  3.     int ow = width;  
  4.     switch (orien)  
  5.     {  
  6.         case 2:  
  7.             img.RotateFlip(RotateFlipType.RotateNoneFlipX);//horizontal flip  
  8.             break;  
  9.         case 3:  
  10.             img.RotateFlip(RotateFlipType.Rotate180FlipNone);//right-top  
  11.             break;  
  12.         case 4:  
  13.             img.RotateFlip(RotateFlipType.RotateNoneFlipY);//vertical flip  
  14.             break;  
  15.         case 5:  
  16.             img.RotateFlip(RotateFlipType.Rotate90FlipX);  
  17.             break;  
  18.         case 6:  
  19.             img.RotateFlip(RotateFlipType.Rotate90FlipNone);//right-top  
  20.             width = height;  
  21.             height = ow;  
  22.             break;  
  23.         case 7:  
  24.             img.RotateFlip(RotateFlipType.Rotate270FlipX);  
  25.             break;  
  26.         case 8:  
  27.             img.RotateFlip(RotateFlipType.Rotate270FlipNone);//left-bottom  
  28.             width = height;  
  29.             height = ow;  
  30.             break;  
  31.         default:  
  32.             break;  
  33.     }  

至此,使用C#旋轉(zhuǎn)圖片的目的就達(dá)到了。

【編輯推薦】

  1. C#代碼與#函數(shù)相互調(diào)用問題集錦
  2. 如何使用泛型達(dá)到代碼重用的目的
  3. 線性鏈表測試方法簡介
  4. 創(chuàng)建一個簡單的線性鏈表
  5. C#事件模型的一個實(shí)例
責(zé)任編輯:book05 來源: cnblogs
相關(guān)推薦

2009-08-20 12:35:41

C#讀取圖片的EXIF

2024-09-11 14:46:48

C#旋轉(zhuǎn)按鈕

2024-07-04 08:26:12

AndroidJPEG圖片

2009-08-19 14:26:58

C# JavaScri

2009-08-18 17:29:02

C#使用指針

2009-08-20 13:23:28

C#使用Crystal

2009-09-01 09:16:57

C#使用SharpZi

2009-08-31 16:12:02

C#使用Singlet

2009-08-25 16:49:44

C#使用if語句

2009-08-14 15:23:10

C#使用ErrorPr

2024-04-19 08:31:40

Android屬性讀取

2009-08-13 13:29:04

C#結(jié)構(gòu)體使用

2009-08-21 15:16:23

C#使用指針

2009-08-27 17:47:21

c#皮膚

2009-08-19 15:18:53

迭代器

2009-08-19 16:42:41

C#如何使用XML

2009-08-13 15:48:57

C#指針

2009-08-11 13:27:22

C#創(chuàng)建Web Ser

2009-08-25 16:29:33

C#使用sqlserv

2009-08-19 17:45:26

C#使用GDI+
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號