我有一些圖像,我需要做一些粗糙的重新大小的工作 - 對於這個例子的目的,讓我們只是說我需要增加寬度和高度一個給定的圖像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