当前位置:网站首页>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;
}
边栏推荐
猜你喜欢

wps插入图片后使图片完整显示

微信核酸检测预约小程序系统毕业设计毕设(4)开题报告

pycharm 修改 pep8 E501 line too long > 0 characters

Taiwan Feiling fm8pb513b MCU provides MCU program development product design

微信核酸检测预约小程序系统毕业设计毕设(5)任务书

切换变换的时候记得使用三元表达式

拿起相机,便是最好的艺术疗愈

【Golang | gRPC】使用gRPC实现简单远程调用

Develop a controller that prohibits deleting namespaces

Embedded ~ introduction
随机推荐
Taiwan Feiling fm8pb513b MCU provides MCU program development product design
MySQL installation and configuration
Aptos教程-参与官方激励测试网(AIT2 激励测试网)
微信核酸检测预约小程序系统毕业设计毕设(3)后台功能
win10 卸载cuda
567. Arrangement in string
面试,关于线程池的那些事
Mysql 备份的三种方式
Solution pour arrêter automatiquement les paquets Jar en cours d'exécution en éteignant le serveur de connexion xshell
ORA-19838 -- 恢复控制文件到备库
Edgenext hit a mixed punch: a lightweight architecture integrating CNN and transformer
应广单片机003烧录器自定义封装使用技巧
台湾飞凌FM8PB513B单片机提供单片机方案开发 产品设计
Viewing technological changes through Huawei Corps (VI): smart highway
Graduation summary
win10 kms activator
No such file or directory: ‘/tmp/tmpxxx/tmpxxx. py‘
Typescript
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
PMS132B单片机TWS数码管蓝牙充电仓方案开发