如何获得的图像从一个URL一个PictureBox? (Windows Mobile的) [英] How to get an image to a pictureBox from an URL? (Windows Mobile)
本文介绍了如何获得的图像从一个URL一个PictureBox? (Windows Mobile的)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
什么和如何使用Compact Framework的时候从一个URL得到一个形象的最佳方式是什么?
What and how is the best way to get an image from an URL when using the Compact Framework?
我用Google搜索左右,但找不到任何像样的答案
I have googled around, but could not find any decent answers.
东西,我发现这个(做了一个函数出来的):
Something i found was this (made a function out of it):
public Bitmap getImageFromUrl()
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(this.SImageUrl);
request.Timeout = 5000; // 5 seconds in milliseconds
request.ReadWriteTimeout = 20000; // allow up to 20 seconds to elapse
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream ms = response.GetResponseStream();
Bitmap imageFromUrl;
using (MemoryStream ms2 = new MemoryStream())
{
int bytes = 0;
byte[] temp = new byte[4096];
while ((bytes = ms.Read(temp, 0, temp.Length)) != 0)
ms2.Write(temp, 0, bytes);
imageFromUrl = new Bitmap(ms2);
}
return imageFromUrl;
}
但它不会显示在PictureBox任何图像。
任何想法?
But it won't show any images in the pictureBox. Any ideas?
由于我提前
推荐答案
我现在发现了一些工作得更好,但由于一个答案史蒂夫丹娜。
这里是我的解决方案:
I now found something that works better, but thanks for an answer Steve Danner. Here is my solution:
public Bitmap getImageFromURL(String sURL)
{
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(sURL);
myRequest.Method = "GET";
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(myResponse.GetResponseStream());
myResponse.Close();
return bmp;
}
这篇关于如何获得的图像从一个URL一个PictureBox? (Windows Mobile的)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文