当前位置:网站首页>C# 检测图片是否被旋转并修改到正真的旋转
C# 检测图片是否被旋转并修改到正真的旋转
2022-07-02 16:19:00 【梅里雪山GIS】
C# 检测图片是否被旋转并修改到正真的旋转
一、在利用jpg合并pdf的过程中发现大量的图片旋转,用看图软件打开旋转的照片发现是正常的,经过对比发现这些照片的image.PropertyItems.Value[0]值和没有发生旋转的照片有差异。故而写了下面的函数处理。
/// <summary>
/// C# 检测图片是否被旋转并修改到正真的旋转
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
public static bool readPictureDegreeAndKiRotate(string path)
{
bool bl = false;
try
{
//获取旋转角度
int rotate = 0;
using (var image = System.Drawing.Image.FromFile(path))
{
foreach (var prop in image.PropertyItems)
{
if (prop.Id == 0x112)
{
if (prop.Value[0] == 6)
rotate = 90;
if (prop.Value[0] == 8)
rotate = -90;
if (prop.Value[0] == 3)
rotate = 180;
prop.Value[0] = 1;
}
}
}
//旋转图片
using (Bitmap bitmap = new Bitmap(path))
{
RotateFlipType rotateFlipType = new RotateFlipType();
if (rotate == 90)
{
rotateFlipType = RotateFlipType.Rotate90FlipNone;
bitmap.RotateFlip(rotateFlipType);
bitmap.Save(path);
}
else if (rotate == -90)
{
rotateFlipType = RotateFlipType.Rotate270FlipNone;
bitmap.RotateFlip(rotateFlipType);
bitmap.Save(path);
}
else if (rotate == 180)
{
rotateFlipType = RotateFlipType.Rotate180FlipNone;
bitmap.RotateFlip(rotateFlipType);
bitmap.Save(path);
}
bitmap.Dispose();
}
bl = true;
}
catch (Exception ex)
{
bl = false;
}
return bl;
}
边栏推荐
- A4988与42步进电机
- Keras深度学习实战——基于VGG19模型实现性别分类
- 外包干了五年,废了...
- 应广单片机(MCU单片机科普)
- Design of the multi live architecture in different places of the king glory mall
- 我的创作纪念日
- 深入理解ThreadLocal
- Wasserstein slim gain with clipping penalty (wsgain-cp) introduction and code implementation -- missing data filling based on generating countermeasure network
- Modbus protocol communication exception
- Simple understanding of cardinality sorting
猜你喜欢
Mysql - opérations de base de la base de données
MySQL --- 数据库的基本操作
能解决 80% 故障的排查思路
MySQL advanced - transaction and index
[golang | grpc] generate certificates using OpenSSL
Linux中,mysql设置job任务自动启动
win10 kms activator
外包干了五年,废了...
Laravel文档阅读笔记-Custom Authentication Login And Registration Using Laravel 8
MySQL -- basic operation of database
随机推荐
售价仅40元,树莓派Pico开发板加入WiFi模块,刚上市就脱销
Unified interface for reading and writing data files in xml/json/ini and ubjson formats
WPS inserts a picture and displays it completely
Detailed explanation of map set
应广单片机开发流程需要注意哪些?
深入理解ThreadLocal
开发一个禁止删除namespace的控制器
Keras深度学习实战——基于VGG19模型实现性别分类
567. Arrangement in string
1288_FreeRTOS中vTaskResume()接口以及中断安全版本接口实现分析
Enter a valid user name and password in the Microsoft LDAP configuration page, and enter a valid user name in the Microsoft LDAP configuration page
Modbus protocol communication exception
wait_ for_ Gap -- restore archive from primary archive to secondary Archive
Longest non repeating subarray
em120.gige. h
求求你们,别再刷 Star 了!这跟“爱国”没关系!
PFC232-SOP8/14/16应广一级可带烧录程序编带
ORA-19838 -- 恢复控制文件到备库
Finally detailed explanation
Easyai notes - machine learning