7

Silverlight API を使用した Windows Phone 8.1 アプリがあります。このイメージをブロブ ストレージからダウンロードしています。

ダウンロードする画像

画像はhttps://[service].blob.core.windows.net/[imagename].pngのようなリンクから取得され、URI を使用するだけで複数のブラウザーで画像を表示およびダウンロードできます。

これを blobstorage の imageuri に基づいた imagebrush として使用したいと思います。

// If we have a returned SAS.
                BitmapImage myOnlineImage = new BitmapImage();
                myOnlineImage.UriSource = new Uri(uploadImage.ImageUri, UriKind.RelativeOrAbsolute);
                //ImageOnlineTest.Source = myOnlineImage;
                var imageBrush = new ImageBrush
                {
                    ImageSource = myOnlineImage,
                    Stretch = Stretch.None
                };
                var source = FindChildShieldCanvas(CanvasImage, imageBrush);

                WriteableBitmap wbm = new WriteableBitmap((BitmapImage)myOnlineImage);
                ImageOnlineTest.Source = wbm;

が正しく作成されていません。myOnlineImage少なくとも、画像を writeablebitmapimage に変換できません (変換から null 例外が発生します)。さらに、imagebrush は空、つまり null です。しかし、私が知る限り、これはそれを行う方法ですか?

だから基本的に

imagebrushURL に基づいて https サイトを作成するにはどうすればよいですか?

4

3 に答える 3

3

画像からビットマップを作成するには、URL を設定する前にビットマップ オブジェクトの初期化を開始する必要があります。

    BitmapImage myOnlineImage = new BitmapImage();
    myOnlineImage.BeginInit();
    myOnlineImage.UriSource = new Uri(uploadImage.ImageUri, UriKind.RelativeOrAbsolute);
    myOnlineImage.EndInit();

    var imageBrush = new ImageBrush
    {
        ImageSource = myOnlineImage,
        Stretch = Stretch.None
    };
    var source = FindChildShieldCanvas(CanvasImage, imageBrush);

    WriteableBitmap wbm = new WriteableBitmap((BitmapImage)myOnlineImage);
    ImageOnlineTest.Source = wbm;
于 2015-11-24T15:49:41.540 に答える
1

次の方法で C# を使用して実行できます。適切なコードをフィールドに置き換えます。

Rectangle rectangle = new Rectangle();
rectangle.StrokeThickness = 10;
rectangle.Height = 200;
rectangle.Width = 100;
rectangle.SetValue(Canvas.LeftProperty, 100d);
rectangle.SetValue(Canvas.TopProperty, 100d);
rectangle.Fill = new ImageBrush(new BitmapImage(new Uri(@"C:\User\xiaorui.dong\Pictures\profile.jpeg")));
于 2015-12-01T11:27:52.027 に答える