c#的内存不足问题,经典问题了吧,就是不会解决啊!帮忙
代码如下:
public void AddShuiYinPic(string path, string Path_syp, string Path_sypf)
{
path = path.Replace(@"\\",@"\");
path = path.Replace("/",@"\");
System.Drawing.Image image = System.Drawing.Image.FromFile(path);
//string changedImage = string.Empty;
if (IsPixelFormatIndexed(image.PixelFormat))
{
MemoryStream ms = new MemoryStream();
Bitmap bmp = new Bitmap(image);//生成位图
bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
image.Dispose();
image = System.Drawing.Image.FromStream(ms, true);
bmp.Dispose();
ms.Close();
ms.Dispose();
}
//System.Drawing.Image image = System.Drawing.Image.FromFile(path);
System.Drawing.Image copyImage = System.Drawing.Image.FromFile(Path_sypf);
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(image);
g.DrawImage(copyImage, new System.Drawing.Rectangle(image.Width - copyImage.Width, 0, copyImage.Width, copyImage.Height), 0, 0, copyImage.Width, copyImage.Height, System.Drawing.GraphicsUnit.Pixel);
g.Dispose();
image.Save(Path_syp);
image.Dispose();
copyImage.Dispose();
}
会出现内存不足的提示,但是代码没啥问题啊,帮助看看吧。谢谢了高手们。