我想旋转图像..我有一个pictureBox 369x276。但是当我旋转时,这个尺寸会减小。图像调整时旋转
在PictureBox sizeMode是PictureBoxSizeMode.StretchImage
这里是我的代码:
Bitmap oldBitmap = (Bitmap)pictureBox1.Image;
float angle = 90;
var newBitmap = new Bitmap(oldBitmap.Width, oldBitmap.Height);
var graphics = Graphics.FromImage(newBitmap);
graphics.TranslateTransform((float)oldBitmap.Width/2, (float)oldBitmap.Height/2);
graphics.RotateTransform(angle);
graphics.TranslateTransform(-(float)oldBitmap.Width/2, -(float)oldBitmap.Height/2);
graphics.DrawImage(oldBitmap, new Point(0, 0));
pictureBox1.Image = newBitmap;
RotateFlip非常棒,如果你想要做的只是90度旋转。 op的代码可以处理任何角度。 – 2013-03-14 17:03:35
thx很多。它的效果很好 – Ladessa 2013-03-14 17:11:39
@ Dan-o非常真实,用一种稍微冗长的方式更新了我的答案,可以在不影响尺寸的情况下将图像旋转任意角度。 – JMK 2013-03-14 17:34:17