0

こんにちは私はwcfレストサービスからビットマップイメージをロードする際に小さな問題に遭遇しています:

    public Image GetImage(int width, int height)
    {
        string uri = string.Format("http://localhost:8000/Service/picture/{0}/{1}", width, height);
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);

        using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
        {
            using (Stream stream = response.GetResponseStream())
            {
                return new Bitmap(stream); //no System.Drawing.Bitmap class in wpf?
            }
        }
    }

wpfのSystem.Drawingクラスがないようですが、どうすればこれを修正できますか?これに関連する別の問題は、ソースをどのように設定するかです。

image1.Source = GetImage(image1.Height, image1.Width); //best overload for this line
// also not sure if source would be correct?

Windowsフォームでは、次のことができます。

pictureBox1.Image = GetImage(pictureBox1.Height, pictureBox1.Width); 

これは問題なく動作しますが、wpfは明らかに私を終わらせないようにしなければなりません!

ここでできる簡単なことがあると本当に期待していますか?

        <GroupBox Height="141" HorizontalAlignment="Left" Name="groupBox1" VerticalAlignment="Top" Width="141" BorderBrush="#FFA3A3A3" Background="#37000000" Margin="1,21,0,0">
            <Image Name="image1" Stretch="Fill"/>
        </GroupBox>
4

1 に答える 1

1

WPF に悩まされることはありません。さらに簡単です。

    <GroupBox Height={Binding Height}" Width="{Binding Width"}>
        <Image Source="{Binding MyImageUrl}" />
    </GroupBox>

ビューモデルは次のようになります

public class ImageViewModel : INotifyPropertyChanged 
{
    public string ImageUrl
    {
        get
        {
            return "your url here";
        }
    }

    public double Width
    {
        get { return "required width"; }
    }

    public double Height
    {
        get { return "required height"; }
    }
}

もちろん、INotifyPropertyChanged を実装する必要があります。

于 2012-04-28T14:11:17.993 に答える