当前位置:网站首页>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;
}
边栏推荐
- 辉芒微IO单片机FT60F010A-URT
- 辉芒微IO单片机FT60F11F-MRB
- Asemi rectifier bridge umb10f parameters, umb10f specifications, umb10f package
- Pms150c Yingguang MCU development case
- Remember to use ternary expressions when switching transformations
- 义隆EM78P153K DIP14单片机 MCU
- 使用NPOI导出Excel文件
- matplotlib的安装教程以及简单调用
- 【Golang | gRPC】使用openssl生成证书
- Experience Alibaba cloud character recognition OCR
猜你喜欢

In Linux, MySQL sets the job task to start automatically

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

PFC232-SOP8/14/16应广一级可带烧录程序编带

win10 kms activator

微信小程序视频分享平台系统毕业设计毕设(8)毕业设计论文模板

Nvidia 显卡 Failed to initialize NVML Driver/library version mismatch 错误解决方案

2 juillet: BitTorrent est sorti; L'acquisition du système commercial linspire; Sony Deployment PlayStation now

How to download wechat payment certificate (API certificate)

Redisson high performance redis distributed lock source code analysis

MySQL --- 数据库的基本概念
随机推荐
基数排序的简单理解
From a professional background, I can't get into a small company for interview
台湾飞凌FM8PB513B单片机提供单片机方案开发 产品设计
2 juillet: BitTorrent est sorti; L'acquisition du système commercial linspire; Sony Deployment PlayStation now
Edgenext hit a mixed punch: a lightweight architecture integrating CNN and transformer
ORA-19838 -- 恢复控制文件到备库
MySQL进阶-事务及索引
Viewing technological changes through Huawei Corps (VI): smart highway
vimium映射鍵
Mb10m-asemi rectifier bridge mb10m
如何下载微信支付证书(API证书)
原厂原装 应广单片机PMS134方案开发应用案例
Development and application case of pms134 scheme of Yingguang single chip microcomputer with original packaging
Mysql - opérations de base de la base de données
应广单片机开发案例
Outsourcing for five years, abandoned
Embedded ~ introduction
详解Kubernetes网络模型
自定义一个loading指令
好评率计算