我使用以下代碼來觀看圖像源:爲什麼圖像的流媒體源無法正常工作?
BitmapImage Art3 = new BitmapImage();
using (FileStream stream = File.OpenRead("c:\\temp\\Album.jpg"))
{
Art3.BeginInit();
Art3.StreamSource = stream;
Art3.EndInit();
}
artwork.Source = Art3;
「藝術品」是其中圖像是應該顯示的XAML對象。該代碼應該不會鎖定圖像,它不會鎖定它,但沒有顯示它,並且默認圖像變成「沒有」......我的猜測是我沒有正確使用該流,並且我的圖像變爲空。幫幫我?
UPDATE:
我現在用下面的代碼,一個朋友向我建議:
BitmapImage Art3 = new BitmapImage();
FileStream f = File.OpenRead("c:\\temp\\Album.jpg");
MemoryStream ms = new MemoryStream();
f.CopyTo(ms);
f.Close();
Art3.BeginInit();
Art3.StreamSource = ms;
Art3.EndInit();
artwork.Source = Art3;
一些奇怪的原因,該代碼返回以下錯誤:
The image cannot be decoded. The image header might be corrupted.
我究竟做錯了什麼?我相信我想加載的圖像不會損壞。
不,那不是我的問題,圖像沒有被加載在所有從源頭抓起,這是我目前的問題是什麼... :( – Thorinair 2010-09-11 07:03:52