2013-03-13 81 views
3

我試圖旋轉用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

+6

肯定的寬度和高度或如果旋轉90°,需要交換「returnBitmap」? – 2013-03-13 14:40:11

+0

我同意以前的評論。您可以將寬度和高度更改爲90°,180°。任何度在這裏看到我的解決方案:[stackoverflow.com:C#,旋轉圖形?](https://stackoverflow.com/questions/5172906/c-rotating-graphics/48725273#48725273) – 2018-02-10 20:38:32

回答

1

如果位圖的寬度大於它是高,你會得到裁剪,當你旋轉90度。您需要在撥打g.TranslateTranform時考慮這一點。

+0

所以我不明白我應該更改... – Jordan 2013-03-13 16:06:24