使用C#旋轉(zhuǎn)圖片:EXIF
一、什么是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 Orientation
- Orientation
- The image orientation viewed in terms of rows and columns.
- Tag = 274 (112.H)
- Type = SHORT
- Count = 1
- Default = 1
- 1 = The 0th row is at the visual top of the image, and the 0th column is the visual left-hand side.
- 2 = The 0th row is at the visual top of the image, and the 0th column is the visual right-hand side.
- 3 = The 0th row is at the visual bottom of the image, and the 0th column is the visual right-hand side.
- 4 = The 0th row is at the visual bottom of the image, and the 0th column is the visual left-hand side.
- 5 = The 0th row is the visual left-hand side of the image, and the 0th column is the visual top.
- 6 = The 0th row is the visual right-hand side of the image, and the 0th column is the visual top.
- 7 = The 0th row is the visual right-hand side of the image, and the 0th column is the visual bottom.
- 8 = The 0th row is the visual left-hand side of the image, and the 0th column is the visual bottom.
- Other = reserved
三、使用C#旋轉(zhuǎn)圖片
- public static void rotating(Bitmap img,ref int width, ref int height, int orien)
- {
- int ow = width;
- switch (orien)
- {
- case 2:
- img.RotateFlip(RotateFlipType.RotateNoneFlipX);//horizontal flip
- break;
- case 3:
- img.RotateFlip(RotateFlipType.Rotate180FlipNone);//right-top
- break;
- case 4:
- img.RotateFlip(RotateFlipType.RotateNoneFlipY);//vertical flip
- break;
- case 5:
- img.RotateFlip(RotateFlipType.Rotate90FlipX);
- break;
- case 6:
- img.RotateFlip(RotateFlipType.Rotate90FlipNone);//right-top
- width = height;
- height = ow;
- break;
- case 7:
- img.RotateFlip(RotateFlipType.Rotate270FlipX);
- break;
- case 8:
- img.RotateFlip(RotateFlipType.Rotate270FlipNone);//left-bottom
- width = height;
- height = ow;
- break;
- default:
- break;
- }
- }
至此,使用C#旋轉(zhuǎn)圖片的目的就達(dá)到了。
【編輯推薦】