当前位置:网站首页>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;
}
边栏推荐
- win10 卸载cuda
- Hbuilderx runs to the mobile phone or simulator and prompts that the device is not found
- 1288_ Implementation analysis of vtask resume() interface and interrupt Security version interface in FreeRTOS
- 【Golang | gRPC】使用gRPC实现简单远程调用
- vimium映射键
- 好玩的免费GM游戏整理汇总
- From a professional background, I can't get into a small company for interview
- How can you omit a large number of switch statements
- Deep understanding of ThreadLocal
- Yingguang MCU development case
猜你喜欢

MySQL -- basic concept of database

win10 kms activator

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

Asemi rectifier bridge umb10f parameters, umb10f specifications, umb10f package

Microsoft LDAP 配置页中输入有效的用户名及密码,microsoft ldap 配置页中输入有效的用户名
![[games101] operation 4 B é zier curve](/img/57/e7a9191b959cb1177b7bd1a439df2a.png)
[games101] operation 4 B é zier curve

微信核酸检测预约小程序系统毕业设计毕设(1)开发概要

Outsourcing for five years, abandoned

一个优秀程序员可抵五个普通程序员!

finally详解
随机推荐
深入理解ThreadLocal
D构造函数问题
Asemi rectifier bridge umb10f parameters, umb10f specifications, umb10f package
应广单片机开发 工规 PMC131 带AD芯片检测电池电压单片机SOP8/14
一个优秀程序员可抵五个普通程序员!
辉芒微IO单片机FT60F11F-MRB
matplotlib的安装教程以及简单调用
Design of the multi live architecture in different places of the king glory mall
Explain kubernetes network model in detail
MySQL -- basic concept of database
Unified interface for reading and writing data files in xml/json/ini and ubjson formats
Two pieces of nature a day! Duan Fengfeng, an alumnus of the University of science and technology of China, was the third Chinese winner of the belby medal
Taiwan Feiling fm8pb513b MCU provides MCU program development product design
Editor编辑器扩展在Scene View添加按钮和logo
应广单片机开发案例
Tips for self defined packaging of Yingguang SCM 003 burner
Easyai notes - machine learning
Develop a controller that prohibits deleting namespaces
巴比特 | 元宇宙每日必读:一千块就能买一个虚拟主播?这是小企业的直播福音还是在“割韭菜”?...
A4988与42步进电机