当前位置:网站首页>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;
}
边栏推荐
- 原厂原装 应广单片机PMS134方案开发应用案例
- qt的内存映射
- Develop a controller that prohibits deleting namespaces
- 一日2篇Nature!中科大校友段镶锋团队纳米材料新成果,曾是贝尔比奖章第三位华人得主...
- Easyai notes - machine learning
- PMS132B单片机TWS数码管蓝牙充电仓方案开发
- [today in history] July 2: BitTorrent came out; The commercial system linspire was acquired; Sony deploys Playstation now
- Problems needing attention in the development and debugging of Yingguang single chip microcomputer
- D constructor problem
- 515. 在每个树行中找最大值
猜你喜欢

【Zuul】com. netflix. zuul. exception. ZuulException: Hystrix Readed time out

【Zuul】com.netflix.zuul.exception.ZuulException: Hystrix Readed time out

win10 kms activator

MySQL -- basic operation of database

My creation anniversary

使用Zadig从0到1搭建持续交付平台
![[today in history] July 2: BitTorrent came out; The commercial system linspire was acquired; Sony deploys Playstation now](/img/16/574eee53720fd609027950b9bf8154.png)
[today in history] July 2: BitTorrent came out; The commercial system linspire was acquired; Sony deploys Playstation now

MySQL --- 數據庫的基本操作

Modbus protocol communication exception
![[games101] operation 4 B é zier curve](/img/57/e7a9191b959cb1177b7bd1a439df2a.png)
[games101] operation 4 B é zier curve
随机推荐
Viewing technological changes through Huawei Corps (VI): smart highway
【Zuul】com.netflix.zuul.exception.ZuulException: Hystrix Readed time out
自定义一个loading指令
一日2篇Nature!中科大校友段镶锋团队纳米材料新成果,曾是贝尔比奖章第三位华人得主...
Vimium mapping key
No such file or directory: ‘/tmp/tmpxxx/tmpxxx. py‘
matplotlib的安装教程以及简单调用
深入理解ThreadLocal
如何开启IDEA的Run Dashboard功能
怎么可以省去大量的switch语句,省去switch语句
MySQL --- 數據庫的基本操作
Aloam code reading and summary
Pfc232-sop8/14/16 should be wide-ranging and can be tape programmed with burning program
一个优秀程序员可抵五个普通程序员!
Two pieces of nature a day! Duan Fengfeng, an alumnus of the University of science and technology of China, was the third Chinese winner of the belby medal
Many scenic spots are temporarily closed due to the typhoon. The provincial culture and tourism department reminds you to pay attention to safety!
体验一下阿里云文字识别OCR
Edgenext hit a mixed punch: a lightweight architecture integrating CNN and transformer
辉芒微IO单片机FT60F11F-MRB
Linux中,mysql设置job任务自动启动