[英]System.Drawing alternative in wpf?
Hi I am running into a small problem with loading a Bitmap image from a wcf rest service: 嗨,我正在从wcf rest服务加载位图图像时遇到一个小问题:
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?
}
}
}
Seems there is no System.Drawing class for wpf so how can I fix this? 似乎没有用于wpf的System.Drawing类,那么如何解决此问题? Another problem related to this is how do I set the source:
与此相关的另一个问题是如何设置源:
image1.Source = GetImage(image1.Height, image1.Width); //best overload for this line
// also not sure if source would be correct?
In windows forms you can do this: 在Windows窗体中,您可以执行以下操作:
pictureBox1.Image = GetImage(pictureBox1.Height, pictureBox1.Width);
Which works fine but wpf obviously has to annoy me to no end! 哪个工作正常,但wpf很显然要惹恼我!
Im really hoping there is something simple that can be done here? 我真的希望这里可以做些简单的事情?
<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>
WPF shouldn't annoy you. WPF不会惹恼您。 It's even easier.
更容易了。
<GroupBox Height={Binding Height}" Width="{Binding Width"}>
<Image Source="{Binding MyImageUrl}" />
</GroupBox>
Your view model could be something like 您的视图模型可能类似于
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"; }
}
}
and of course you would need to implement INotifyPropertyChanged. 当然,您将需要实现INotifyPropertyChanged。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.