当前位置:网站首页>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;
}
边栏推荐
- Laravel框架安装时遇到的坑
- 架构设计——ID生成器「建议收藏」
- 567.字符串中的排列
- PMS150C应广单片机开发案例
- 使用Zadig从0到1搭建持续交付平台
- Pfc232-sop8/14/16 should be wide-ranging and can be tape programmed with burning program
- 怎么可以省去大量的switch语句,省去switch语句
- Pms132b single chip microcomputer TWS digital tube Bluetooth charging chamber program development
- win10 kms activator
- Customize a loading instruction
猜你喜欢

Pfc232-sop8/14/16 should be wide-ranging and can be tape programmed with burning program

1288_FreeRTOS中vTaskResume()接口以及中断安全版本接口实现分析
![[golang | grpc] use grpc to realize simple remote call](/img/93/ae6eba2ba65d6e23bd00f45d04a2ed.png)
[golang | grpc] use grpc to realize simple remote call

515. 在每个树行中找最大值

MySQL安装与配置

MySQL --- 數據庫的基本操作

From a professional background, I can't get into a small company for interview

Embedded ~ introduction

Linux中,mysql设置job任务自动启动

Easyai notes - machine learning
随机推荐
辉芒微IO单片机FT60F11F-MRB
应广单片机开发 工规 PMC131 带AD芯片检测电池电压单片机SOP8/14
From a professional background, I can't get into a small company for interview
我的创作纪念日
1288_ Implementation analysis of vtask resume() interface and interrupt Security version interface in FreeRTOS
[target tracking] |siamfc
【Zuul】com.netflix.zuul.exception.ZuulException: Hystrix Readed time out
Edgenext hit a mixed punch: a lightweight architecture integrating CNN and transformer
读写 XML/JSON/INI 和 UBJSON 等格式的数据文件的统一接口
Clé de cartographie vimium
567. Arrangement in string
Huimang micro IO MCU ft60f010a-urt
把xshell连接服务器关掉,运行的jar包就自动停止的解决方案
Ora-19838 -- restore control files to the standby database
松翰SN8P2511 SOP8单片机 可代烧录 提供单片机方案开发 单片机解密
【Golang | gRPC】使用openssl生成证书
Unified interface for reading and writing data files in xml/json/ini and ubjson formats
Vimium mapping key
qt的内存映射
基数排序的简单理解