当前位置:网站首页>C # detect whether the picture is rotated and modified to the true rotation
C # detect whether the picture is rotated and modified to the true rotation
2022-07-02 18:08:00 【Meili Snow Mountain GIS】
C# Check whether the picture is rotated and modified to the true rotation
One 、 Using jpg Merge pdf Found a lot of image rotation in the process , It's normal to open the rotating photos with the picture viewing software , After comparison, I found these photos image.PropertyItems.Value[0] The value is different from the photo without rotation . Therefore, the following function processing is written .
/// <summary>
/// C# Check whether the picture is rotated and modified to the true rotation
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
public static bool readPictureDegreeAndKiRotate(string path)
{
bool bl = false;
try
{
// Get the angle of rotation
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;
}
}
}
// Rotate the picture
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;
}
边栏推荐
猜你喜欢
微信核酸检测预约小程序系统毕业设计毕设(4)开题报告
[today in history] July 2: BitTorrent came out; The commercial system linspire was acquired; Sony deploys Playstation now
WPS inserts a picture and displays it completely
一个优秀程序员可抵五个普通程序员!
[golang | grpc] generate certificates using OpenSSL
From a professional background, I can't get into a small company for interview
ORA-19838 -- 恢复控制文件到备库
Linux中,mysql设置job任务自动启动
微信小程序视频分享平台系统毕业设计毕设(7)中期检查报告
Editor编辑器扩展在Scene View添加按钮和logo
随机推荐
Editor Editor Extension add button and logo in scene view
Yingguang MCU development case
Pms150c Yingguang MCU development case
qt的内存映射
Yingguang single chip microcomputer development specification pmc131 with AD chip to detect battery voltage single chip microcomputer sop8/14
finally详解
515. Find the maximum value in each tree row
Huimang micro IO MCU ft60f11f-mrb
Problems needing attention in the development and debugging of Yingguang single chip microcomputer
515. 在每个树行中找最大值
微信核酸检测预约小程序系统毕业设计毕设(4)开题报告
PMS150C应广单片机开发案例
Solution pour arrêter automatiquement les paquets Jar en cours d'exécution en éteignant le serveur de connexion xshell
Mysql 备份的三种方式
vi/vim 删除:一行, 一个字符, 单词, 每行第一个字符 命令
MySQL --- 數據庫的基本操作
MySQL --- 数据库的基本概念
Laravel框架安装时遇到的坑
Mysql - opérations de base de la base de données
原装应广单片机 MCU芯片PMS152 SOP8封装 单片机开发