我有一個圖片框,大小爲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