当前位置:网站首页>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;
}
边栏推荐
- Pms150c Yingguang MCU development case
- Develop a controller that prohibits deleting namespaces
- Linux中,mysql设置job任务自动启动
- How can you omit a large number of switch statements
- Mysql 备份的三种方式
- Design of the multi live architecture in different places of the king glory mall
- 怎么可以省去大量的switch语句,省去switch语句
- Asemi rectifier bridge umb10f parameters, umb10f specifications, umb10f package
- 基数排序的简单理解
- How to download wechat payment certificate (API certificate)
猜你喜欢
Develop a controller that prohibits deleting namespaces
微信小程序视频分享平台系统毕业设计毕设(7)中期检查报告
应广单片机开发 工规 PMC131 带AD芯片检测电池电压单片机SOP8/14
开发一个禁止删除namespace的控制器
The price is only 40 yuan. Pico development board of raspberry pie is added with WiFi module, and it is out of stock as soon as it comes into the market
MySQL --- 数据库的基本操作
台湾飞凌FM8PB513B单片机提供单片机方案开发 产品设计
Experience Alibaba cloud character recognition OCR
Mysql - opérations de base de la base de données
ORA-19838 -- 恢复控制文件到备库
随机推荐
PMS150C应广单片机开发案例
[golang | grpc] use grpc to realize simple remote call
深入理解ThreadLocal
Mb10m-asemi rectifier bridge mb10m
Develop a controller that prohibits deleting namespaces
wait_for_gap -- 从主库归档备库恢复归档
MySQL installation and configuration
Yilong em78p153k dip14 MCU
Asemi rectifier bridge umb10f parameters, umb10f specifications, umb10f package
Vimium mapping key
The price is only 40 yuan. Pico development board of raspberry pie is added with WiFi module, and it is out of stock as soon as it comes into the market
1288_ Implementation analysis of vtask resume() interface and interrupt Security version interface in FreeRTOS
义隆EM78P153K DIP14单片机 MCU
wps插入图片后使图片完整显示
Aptos教程-参与官方激励测试网(AIT2 激励测试网)
能解决 80% 故障的排查思路
Nvidia 显卡 Failed to initialize NVML Driver/library version mismatch 错误解决方案
Linux中,mysql设置job任务自动启动
Ora-19838 -- restore control files to the standby database
【Golang | gRPC】使用openssl生成证书