我有一个图片框,大小为710x238,我正在使用它来显示更大的图像。当我加载图像时,它会加载图像而不会扭曲它。它效果很好。但是,当我旋转图像,并尝试在PictureBox中显示该图像时,图像大小更改为正方形...旋转PictureBox更改大小
如何随图像一起旋转PictureBox以便旋转图像不失真?
这里是我的代码
pictureBox1.SizeMode = PictureBoxSizeMode.Zoom; //property for load without distorting
和旋转代码(此代码将图像旋转......我想旋转图片框)
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;
我如何可以旋转图片框?我想旋转PictureBox以及位图。
但图片框会扭曲的形象。 ..或没有? – Ladessa 2013-03-14 13:32:19
它会将图像剪切到PictureBox的边界,但不会“扭曲”它(拉伸/缩放) – Kohanz 2013-03-14 13:37:19
但我需要图像在PictureBox中显示完整,PictureBoxSizeMode.Zoom可以工作,但旋转时会调整图像的大小错误 – Ladessa 2013-03-14 13:38:24