当前位置:网站首页>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;
}
边栏推荐
- 利用DOSBox运行汇编超详细步骤「建议收藏」
- win10 kms activator
- Remember to use ternary expressions when switching transformations
- Songhan sn8p2511 sop8 single chip microcomputer can be used for burning, providing single chip microcomputer scheme development and single chip microcomputer decryption
- 微信小程序视频分享平台系统毕业设计毕设(8)毕业设计论文模板
- android之循环定时器实现,实现定Android时缓存清理
- Development of original Yingguang MCU chip pms152 sop8 encapsulated MCU
- 毕业总结
- How can you omit a large number of switch statements
- php获取两个时间戳之间相隔多少天多少小时多少分多少秒
猜你喜欢
Asemi rectifier bridge umb10f parameters, umb10f specifications, umb10f package
Embedded ~ introduction
Troubleshooting ideas that can solve 80% of faults
wait_for_gap -- 从主库归档备库恢复归档
1288_FreeRTOS中vTaskResume()接口以及中断安全版本接口实现分析
[golang | grpc] use grpc to realize simple remote call
515. Find the maximum value in each tree row
自定义一个loading指令
详解Kubernetes网络模型
Develop a controller that prohibits deleting namespaces
随机推荐
MySQL --- 數據庫的基本操作
微信核酸检测预约小程序系统毕业设计毕设(3)后台功能
Pfc232-sop8/14/16 should be wide-ranging and can be tape programmed with burning program
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
win10 kms activator
Songhan sn8p2511 sop8 single chip microcomputer can be used for burning, providing single chip microcomputer scheme development and single chip microcomputer decryption
应广PMC131 SOP16 16pin八位单片机
如何开启IDEA的Run Dashboard功能
Taiwan Feiling fm8pb513b MCU provides MCU program development product design
C# 检测图片是否被旋转并修改到正真的旋转
MySQL --- 数据库的基本操作
Easyai notes - deep learning
应广单片机PMS150/PMC150/PMS150C消费类单片机
android之循环定时器实现,实现定Android时缓存清理
Customize a loading instruction
面试,关于线程池的那些事
What should we pay attention to in the development process of Yingguang single chip microcomputer?
Deep understanding of ThreadLocal
读写 XML/JSON/INI 和 UBJSON 等格式的数据文件的统一接口