有什么办法可以减少内存?
是的,他们是:不要从图像本身创建内存流,而是使用它的缩略图。
这是如何执行此操作的示例代码:
private void button1_Click(object sender, EventArgs e)
{
Image.GetThumbnailImageAbort myCallback = new Image.GetThumbnailImageAbort(ThumbnailCallback);
Bitmap myBitmap = new Bitmap(@"C:\Documents and Settings\Sameh\My Documents\My Pictures\Picture\Picture 004.jpg"); //3664 x 2748 = 3.32 MB
Image myThumbnail = myBitmap.GetThumbnailImage(myBitmap.Width / 100, myBitmap.Height / 100 , myCallback, IntPtr.Zero);
//now use your thumbnail as you like
myThumbnail.Save(@"C:\Documents and Settings\Sameh\My Documents\My Pictures\Picture\Thumbnail 004.jpg");
//the size of the saved image: 36 x 27 = 2.89 KB
//you can create your memory stream from this thumbnail now
}
public bool ThumbnailCallback()
{
return false;
}
这里有更多关于解决方案的细节。