我有一些图片需要进行粗略的重新调整大小 -- 为了举例,假设我需要将给定图像的宽度和高度增加4个像素。
我不确定为什么调用Graphics.DrawImage()会抛出OOM错误 -- 如果您有任何建议,将不胜感激。
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);
}
}