当前位置:网站首页>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;
}
边栏推荐
- Does pytorch support 32 bits?
- [nonlinear control theory]7_ High gain and High Frequency
- wait_ for_ Gap -- restore archive from primary archive to secondary Archive
- 架构设计——ID生成器「建议收藏」
- 售价仅40元,树莓派Pico开发板加入WiFi模块,刚上市就脱销
- Easyai notes - deep learning
- vimium映射鍵
- Solution pour arrêter automatiquement les paquets Jar en cours d'exécution en éteignant le serveur de connexion xshell
- A4988与42步进电机
- 515. 在每个树行中找最大值
猜你喜欢
随机推荐
Wasserstein Slim GAIN with Clipping Penalty(WSGAIN-CP)介绍及代码实现——基于生成对抗网络的缺失数据填补
Customize a loading instruction
From a professional background, I can't get into a small company for interview
Bluetooth technology | new working mode of wearable devices of the Internet of things, and Bluetooth ble helps the new working mode
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
WPS inserts a picture and displays it completely
如何下载微信支付证书(API证书)
好评率计算
567. Arrangement in string
MySQL --- 数据库的基本操作
qt的内存映射
Detailed explanation of map set
Keras深度学习实战——基于VGG19模型实现性别分类
Finally detailed explanation
Huimang micro IO MCU ft60f11f-mrb
[games101] operation 4 B é zier curve
一个优秀程序员可抵五个普通程序员!
Typescript
MySQL -- basic concept of database
2 juillet: BitTorrent est sorti; L'acquisition du système commercial linspire; Sony Deployment PlayStation now








