当前位置:网站首页>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;
}
边栏推荐
- Asemi rectifier bridge umb10f parameters, umb10f specifications, umb10f package
- 王者荣耀商城异地多活架构设计
- Modbus protocol communication exception
- 深入理解ThreadLocal
- ORA-19838 -- 恢复控制文件到备库
- 架构设计——ID生成器「建议收藏」
- My creation anniversary
- 1288_FreeRTOS中vTaskResume()接口以及中断安全版本接口实现分析
- 把xshell连接服务器关掉,运行的jar包就自动停止的解决方案
- Yingguang single chip microcomputer development specification pmc131 with AD chip to detect battery voltage single chip microcomputer sop8/14
猜你喜欢
开发一个禁止删除namespace的控制器
Mysql - opérations de base de la base de données
[today in history] July 2: BitTorrent came out; The commercial system linspire was acquired; Sony deploys Playstation now
[golang | grpc] generate certificates using OpenSSL
好玩的免费GM游戏整理汇总
finally详解
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
应广单片机开发 工规 PMC131 带AD芯片检测电池电压单片机SOP8/14
pytorch支持32位吗?
wps插入图片后使图片完整显示
随机推荐
我的创作纪念日
Alibaba cloud sub account - Permission Policy - full control permission granted to an account and an OSS bucket
vimium映射鍵
Android cycle timer implementation, to achieve fixed Android cache cleaning
Laravel框架安装时遇到的坑
Easyai notes - machine learning
567. Arrangement in string
Development and application case of pms134 scheme of Yingguang single chip microcomputer with original packaging
自定义一个loading指令
Huimang micro IO MCU ft60f010a-urt
Solution pour arrêter automatiquement les paquets Jar en cours d'exécution en éteignant le serveur de connexion xshell
Modbus protocol communication exception
MySQL -- basic concept of database
把xshell連接服務器關掉,運行的jar包就自動停止的解决方案
Redisson 高性能 Redis 分布式锁源码分析
2 juillet: BitTorrent est sorti; L'acquisition du système commercial linspire; Sony Deployment PlayStation now
原装应广单片机 MCU芯片PMS152 SOP8封装 单片机开发
Clé de cartographie vimium
wait_for_gap -- 从主库归档备库恢复归档
Deep understanding of ThreadLocal