【发布时间】:2024-01-10 13:18:01
【问题描述】:
我刚刚经历了一堆东西,试图弄清楚如何让图像旋转。这行得通,但现在它正在剪辑,我不确定如何让它停止......我正在使用这个 rotateImage 方法:
public static Image RotateImage(Image img, float rotationAngle)
{
//create an empty Bitmap image
Bitmap bmp = new Bitmap(img.Width, img.Height);
//turn the Bitmap into a Graphics object
Graphics gfx = Graphics.FromImage(bmp);
//now we set the rotation point to the center of our image
gfx.TranslateTransform((float)bmp.Width / 2, (float)bmp.Height / 2);
//now rotate the image
gfx.RotateTransform(rotationAngle);
gfx.TranslateTransform(-(float)bmp.Width / 2, -(float)bmp.Height / 2);
//set the InterpolationMode to HighQualityBicubic so to ensure a high
//quality image once it is transformed to the specified size
gfx.InterpolationMode = InterpolationMode.HighQualityBicubic;
//now draw our new image onto the graphics object
gfx.DrawImage(img, new System.Drawing.Point(0, 0));
//dispose of our Graphics object
gfx.Dispose();
//return the image
return bmp;
}
我尝试将空位图放大,但这只适用于一侧,因为图像固定在位图的左上角。任何想法将不胜感激!
【问题讨论】:
-
vb.net 在 SO 上也涵盖了这一点。 *.com/questions/23277221/…
标签: c# image rotation clipping