2012-10-09 41 views
1

我有一個圖片String myimg = "images.jpg";,我想設置像一個ImageStreammediaHistoryItem的ImageStream來源

我試過這段代碼:

if (mediaHistoryItem.ImageStream == null) 
{ 
    StreamResourceInfo sri = Application.GetResourceStream(new Uri("real.jpg", UriKind.Relative)); 
    Stream stream = sri.Stream; 
    mediaHistoryItem.ImageStream = stream; 
} 

,但它給我的異常NullreferenceException

+2

那麼,什麼是空的。你是否檢查哪條線給你例外? – Vale

回答

3

確保你的圖片:real.jpg的屬性:build action是「content」而FilePath是正確的。

如果圖像的生成操作是「資源」你應該使用路徑:[項目];組件/ real.jpg

+0

在這裏閱讀http://www.windowsphonegeek.com/tips/wp7-working-with-images-content-vs-resource-build-action – onmyway133

+0

它現在讓你非常痛快(Merci Bouceaup) – Tapho