有什麼辦法可以減少內存嗎?
是的他們是:不要從圖像本身創建你的記憶流,而是使用它的縮略圖。
這裏是如何做到這一點的樣本代碼:
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;
}
而且here is more details有關解決方案。
Samesh,謝謝你的回覆..我不熟悉GetThumbnailImage()。使用它有什麼缺點嗎?我能看到整個圖像嗎? – codematrix 2010-05-21 04:43:52
我可以看到的唯一缺點是使用總是返回false的回調方法!但這是微軟給出的樣本的工作原理!請參閱提供的鏈接瞭解更多詳情。至於整個圖像:你會看到圖像的**縮略圖**;即**全**圖像的縮小版本。請閱讀提供的鏈接中的備註部分,這很重要。 – 2010-05-21 05:06:25