我試圖在Windows Phone應用程序加載圖像
這裏從嵌入式資源加載圖像是我的項目設置:
模塊1 = Phone應用程序
單詞數= ClassLibrary.dll
Module1調用Module2爲手機應用程序創建所有數據對象。
當Module2創建對象時,我想從資源加載圖像。
資源是「爲Default.png」,並保存在「圖像」目錄(生成操作=嵌入的資源,複製到輸出目錄=一直拷貝)
我使用的代碼產生一個異常
ex = {"The request is not supported. "}
下面是代碼:
private void LoadImage()
{
Assembly curAssembly = null;
curAssembly = Assembly.GetExecutingAssembly();
string [] names = curAssembly.GetManifestResourceNames();
// names[0] = "Storage.Images.Default.png"
// so I know I am using the correct name
Stream resStream = curAssembly.GetManifestResourceStream("Storage.Images.Default.png");
BitmapImage bitMapImage = new BitmapImage();
try
{
bitMapImage.SetSource(resStream);
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString());
}
}
你能幫助一個新手了呢? 感謝
謝謝你的方法...我會給這些嘗試...但他們不回答我的問題,爲什麼我無法加載資源,即使資源在模塊內,如GetManifestResourceNames所示? – user3174075