我在ImageBrush
从Stream
. 以下代码用于使用 填充Rectangle
WPF ImageBrush
:
ImageBrush imgBrush = new ImageBrush();
imgBrush.ImageSource = new BitmapImage(new Uri("\\image.png", UriKind.Relative));
Rectangle1.Fill = imgBrush;
我想要做的是调用 aWebRequest
并获取 a Stream
。然后我想使用Stream
图像填充我的矩形。这是代码:
ImageBrush imgBrush = new ImageBrush();
WebRequest request = WebRequest.Create(iconurl);
WebResponse response = request.GetResponse();
Stream s = response.GetResponseStream();
imgBrush.ImageSource = new BitmapImage(s); // Here is the problem
Rectangle1.Fill = imgBrush;
问题是我不知道如何设置我的imgBrush.ImageSource
using response.GetResponseStream()
. 我怎样才能Stream
在我的ImageBrush
?