1

Windows8用のMetroUIアプリで作業しており、プロジェクトフォルダーから画像を取得しようとしています。

これが私の最初のコードです:

public static Image GetImage(string path, int width, int height, int margin)
    {
        Image img = new Image();
        img.Width = width;
        img.Height = height;
        img.Margin = new Windows.UI.Xaml.Thickness(margin);

        BitmapImage bi = new BitmapImage(new Uri(path, UriKind.Absolute));

        img.Source = bi;

        return img;
    }

そして、メソッド呼び出し:

Image = Extension.GetImage("Classe;component/Images/faq.png", 100, 100, 0);

そしてエラー:

Exception:Thrown: "Invalid URI: The format of the URI could not be determined." (System.UriFormatException)
A System.UriFormatException was thrown: "Invalid URI: The format of the URI could not be determined."

URIの種類を相対に変更した場合:

Exception:Thrown: "The given System.Uri cannot be converted into a Windows.Foundation.Uri. Please see http://go.microsoft.com/fwlink/?LinkID=215849 for details." (System.ArgumentException)
A System.ArgumentException was thrown: "The given System.Uri cannot be converted into a Windows.Foundation.Uri. Please see http://go.microsoft.com/fwlink/?LinkID=215849 for details."

画像パスはImages/faq.pngです。コンテンツに設定し、常にコピーします。

4

1 に答える 1

0

Windows.Foundation.Uriのドキュメントを見ると、WinRTは相対URIをサポートしていないようです。MSは、WinRTリソース用にさらに別のURI形式を発明しました。

このようなものを試して、それが機能するかどうかを確認してください。

new Uri("Classe://MyAssembly/component/Images/faq.png") 

注:実際のアセンブリ名は追加しないでください。MyAssemblyパーツはリテラルテキストです。

于 2012-08-10T16:16:07.763 に答える