【发布时间】:2013-03-13 14:33:12
【问题描述】:
我正在尝试使用 C# 旋转图片,并且正在使用以下代码:
///create a new empty bitmap to hold rotated image
Bitmap returnBitmap = new Bitmap(newBMP.Width, newBMP.Height);
//make a graphics object from the empty bitmap
Graphics g = Graphics.FromImage(returnBitmap);
//move rotation point to center of image
g.TranslateTransform((float)newBMP.Width / 2, (float)newBMP.Height / 2);
//rotate
g.RotateTransform(-90);
//move image back
g.TranslateTransform(-(float)newBMP.Width / 2, -(float)newBMP.Height / 2);
//draw passed in image onto graphics object
g.DrawImage(newBMP, new Point(0, 0));
newBMP 是我从表单中获取的位图,我正在更改它的大小。然后我想旋转它,但是当我尝试上面的代码时,它会切割图片的顶部和底部。
完成所有这些后,我将新图片保存在服务器上。
一切正常,除了旋转...
有人发现问题了吗?
解决了我用这个:C# rotate bitmap 90 degrees
【问题讨论】:
-
如果旋转 90°,确定宽度和高度或
returnBitmap需要交换? -
我同意前面的评论。您可以将宽度和高度更改为 90°、180°。对于任何学位,请在此处查看我的解决方案:stackoverflow.com: C#, rotating Graphics?