【发布时间】:2014-07-31 17:18:41
【问题描述】:
这是我的问题:
此方法在 50 毫秒的计时器上重复。 从程序启动到及时转发,该进程的 RAM 内存不断增长,最后调试器将“内存不足错误”抛出到加粗的行(drawimage 方法)。
是否有人可以帮助我找到避免这种情况的解决方案并解释为什么会发生这种情况?
PS。我的目标是不断旋转图片框的背景图像。我知道也许我可以直接在表格上而不是在图片框上绘图,但是如果图片框有解决方案,我会很高兴:p
谢谢!
public static Bitmap RotateImage(Image image, PointF offset, float angle)
{
if (image == null)
throw new ArgumentNullException("image");
//create a new empty bitmap to hold rotated image
Bitmap rotatedBmp = new Bitmap(image.Width, image.Height);
rotatedBmp.SetResolution(image.HorizontalResolution, image.VerticalResolution);
//make a graphics object from the empty bitmap
Graphics g = Graphics.FromImage(rotatedBmp);
//Put the rotation point in the center of the image
g.TranslateTransform(offset.X, offset.Y);
//rotate the image
g.RotateTransform(angle);
//move the image back
g.TranslateTransform(-offset.X, -offset.Y);
//draw passed in image onto graphics object
**g.DrawImage(image, new PointF(0, 0));**
return rotatedBmp;
}
【问题讨论】:
标签: c# bitmap background-image image-rotation