0
我需要做一个需要oauth的GET请求,并在图像中显示一个页面。有没有办法做到这一点,而不建立一个自定义webrequest或httpwebrequest?你如何从一个字节[]或从一个MemoryStream中获取WP7中的System.Windows.Controls.Image?
我需要做一个需要oauth的GET请求,并在图像中显示一个页面。有没有办法做到这一点,而不建立一个自定义webrequest或httpwebrequest?你如何从一个字节[]或从一个MemoryStream中获取WP7中的System.Windows.Controls.Image?
如果是图像,请确保您正在以二进制数据的形式读取数据流。
喜欢的东西:
var httpRequest = (HttpWebRequest)ar.AsyncState;
var httpResponse = (HttpWebResponse)httpRequest.EndGetResponse(ar);
int lengthInBytes = Convert.ToInt32(httpResponse.ContentLength);
BinaryReader br = new BinaryReader(httpResponse.GetResponseStream());
byte[] imageInBytes = new byte[lengthInBytes];
using (br)
{
for (int i = 0; i < lengthInBytes; i++)
{
imageInBytes[i] = br.ReadByte();
}
}
DispatcherHelper.CheckBeginInvokeOnUI(() =>
{
MemoryStream rawBytesStream = new MemoryStream(imageInBytes);
BitmapImage img = new BitmapImage();
img.SetSource(rawBytesStream);
imageInUI.Source = img;
});
你为什么要问这个问题两次? – 2011-04-18 19:58:57
[HTTPWebRequest GET with a OAuth Header for Windows Phone上的图像]的可能重复(http://stackoverflow.com/questions/5699572/httpwebrequest-get-with-oauth-header-for-an-image-on-windows-电话) – 2011-04-18 19:59:23