2011-07-15 79 views

回答

1

here它被描述:

void proxy_GetImageCompleted(object sender, GetImageCompletedEventArgs e) 
{ 
    MemoryStream stream = new MemoryStream(e.Result); 
    BitmapImage b = new BitmapImage(); 
    b.SetSource(stream); 
    imgImage.Source = b; 
} 
1

的System.Windows.Controls.Image.Source屬性的類型System.Windows.Media.ImageSource的 甲System.Windows.Media.Imaging.BitmapImage是派生自ImageSource。

而BitmapImage有一個SetSource(Stream streamsource)方法。

所以用下面的代碼,你可以從一個數據流添加圖像:

Stream inStream = [your MemoryStream]; 

BitmapImage tempImage = new BitmapImage(); 
tempImage.SetSource(inStream); 

YourControlsImage.Source = tempImage; 

MSDN鏈接:

Image.Source Property

BitmapSource.SetSource Method

BitmapImage Class