C#实现根据图片的EXIF自动调整图片方向

简介: 一、什么是 EXIF    Exif是英文Exchangeable Image File(可交换图像文件)的缩写,最初由日本电子工业发展协会(JEIDA --Japan Electronic Industry Development Association) 制订,目前的最新版本是发表于2002年04月的2.21 版。

一、什么是 EXIF

  

Exif是英文 Exchangeable Image File(可交换图像文件)的缩写,最初由日本电子工业发展协会(JEIDA --Japan Electronic Industry Development Association) 制订,目前的最新版本是发表于2002年04月的2.21 版。国际标准化组织(ISO)正在制订的相机文件设计标准(DCF -- Design role for Camera File system)可能以Exif2.1为基础。

      所有的JPEG文件以字符串“0xFFD8”开头,并以字符串“0xFFD9”结束。文件头中有一系列“0xFF??”格式的字符串,称为“标识”,用来标记JPEG文件的信息段。“0xFFD8”表示图像信息开始,“0xFFD9”表示图像信息结束,这两个标识后面没有信息,而其它标识紧跟一些信息字符。

  0xFFE0 -- 0xFFEF之间的标识符称为“应用标记”,没有被常规JPEG文件利用,Exif正是利用这些信息串记录拍摄信息如快门速度、光圈值等,甚至可以包括全球定位信息。其中拍摄方向的ID为“0x0112”,有1至8共8种值。



二、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#旋转图片

Code
        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# Windows
C# WPF 显示图片和视频显示 EmuguCv、AForge.Net测试
原文:C# WPF 显示图片和视频显示 EmuguCv、AForge.Net测试 WPF 没有用到 PictureBox, 而是用Image代替. 下面我试着加载显示一个图片 。 XAML CS Attempt 1: ImageMy_Image=newImage(Openfile.
1765 0
|
25天前
|
API C# 数据安全/隐私保护
C# 实现网页内容保存为图片并生成压缩包
C# 实现网页内容保存为图片并生成压缩包
|
6月前
C#WPF 图片在显示时没有问题,但在运行时图片显示不出来的解决
选中项目,点击右上角的显示全部文件按钮,会将默认隐藏的文件显示出来,选中所需图片,右键,添加到项目,然后选择图片查看属性,生成操作选择resource。完毕。本人目前的解决方案。
258 41
C#WPF 图片在显示时没有问题,但在运行时图片显示不出来的解决
|
4月前
|
API C#
C# 调用系统“API“设置图片为“桌面壁纸“
C# 调用系统“API“设置图片为“桌面壁纸“
|
6月前
|
C#
C# 图片RGB处理判断
C# 图片RGB处理判断 需要:根据一张原始图的RGB平均值和新的图片的RGB平均值的差距,来判断图中是否出现除原图中物体外的其他物体 前提:.Net framework 4.8 及以上 示例代码: 程序集:using System;using System.Drawing;using System.Drawing.Drawing2D;using System.Drawing.Imagin...
21 0
|
9月前
|
人工智能 文字识别 API
C# 10分钟完成百度图片提取文字(文字识别)——入门篇
C# 10分钟完成百度图片提取文字(文字识别)——入门篇
|
12月前
|
算法 定位技术 C#
C#开发:不规则裁切图片
C#开发:不规则裁切图片
118 0
|
区块链 C#
C#实现把图片转换为ico格式
C#实现把图片转换为ico格式
592 0
|
C# 图形学
C#裁剪图片的方法
C#裁剪图片的方法
254 0
如何在 C#中的listView 控件中显示图片?
如何在 C#中的listView 控件中显示图片?
954 0
如何在 C#中的listView 控件中显示图片?