C# rotate bitmap 90 degrees(C# 旋转位图 90 度)
问题描述
我正在尝试使用以下函数将位图旋转 90 度.它的问题在于,当高度和宽度不相等时,它会切断图像的一部分.
I'm trying to rotate a bitmap 90 degrees using the following function. The problem with it is that it cuts off part of the image when the height and width are not equal.
注意 returnBitmap width = original.height 和它的 height = original.width
Notice the returnBitmap width = original.height and it's height = original.width
谁能帮我解决这个问题或指出我做错了什么?
Can anyone help me solve this issue or point out what I'm doing wrong?
private Bitmap rotateImage90(Bitmap b)
{
Bitmap returnBitmap = new Bitmap(b.Height, b.Width);
Graphics g = Graphics.FromImage(returnBitmap);
g.TranslateTransform((float)b.Width / 2, (float)b.Height / 2);
g.RotateTransform(90);
g.TranslateTransform(-(float)b.Width / 2, -(float)b.Height / 2);
g.DrawImage(b, new Point(0, 0));
return returnBitmap;
}
推荐答案
这个:
private void RotateAndSaveImage(String input, String output)
{
//create an object that we can use to examine an image file
using (Image img = Image.FromFile(input))
{
//rotate the picture by 90 degrees and re-save the picture as a Jpeg
img.RotateFlip(RotateFlipType.Rotate90FlipNone);
img.Save(output, System.Drawing.Imaging.ImageFormat.Jpeg);
}
}
这篇关于C# 旋转位图 90 度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!