我有一些图像,我需要做一些粗糙的重新大小的工作 - 对于这个例子的目的,让我们只是说我需要增加宽度和高度一个给定的图像4个像素。 我不确定为什么要调用Graphics.DrawImage()抛出一个OOM - 任何建议在这里将不胜感激。Graphics.DrawImage() - 抛出内存异常
class Program
{
static void Main(string[] args)
{
string filename = @"c:\testImage.png";
// Load png from stream
FileStream fs = new FileStream(filename, FileMode.Open);
Image pngImage = Image.FromStream(fs);
fs.Close();
// super-hacky resize
Graphics g = Graphics.FromImage(pngImage);
g.DrawImage(pngImage, 0, 0, pngImage.Width + 4, pngImage.Height + 4); // <--- out of memory exception?!
// save it out
pngImage.Save(filename, System.Drawing.Imaging.ImageFormat.Png);
}
}
您可以在基于原始图像的'Graphics'对象中绘制较大的图像吗? – FlyingStreudel 2013-03-15 17:27:54