开发者

How do i buffer an image from external link

I have a external link with an image which i want to stream, but i get this error when i try.

开发者_如何学Cerror "URI formats are not supported."

I tried to stream: Stream fileStream = new FileStream("http://www.lokeshdhakar.com/projects/lightbox2/images/image-2.jpg", FileMode.Open); byte[] fileContent = new byte[fileStream.Length];

can anyone put some light on this.

Thanks


The FileStream contructor you are using must be provided with a path on your local harddrive and not with an external URL.

You are probably looking for this:

string url = "http://www.lokeshdhakar.com/projects/lightbox2/images/image-2.jpg";
HttpWebRequest httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);
HttpWebResponse httpWebReponse = (HttpWebResponse)httpWebRequest.GetResponse();
Stream stream = httpWebReponse.GetResponseStream();

Probably also for this:

Image pic = Image.FromStream(stream);
MemoryStream ms = new MemoryStream();
pic.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
Byte[] arr = ms.ToArray();


FileStream doesn't support the opening files over the internet.

Try this:

var webClient = new WebClient();
using(var fileStream = webClient.OpenRead("http://www.lokeshdhakar.com/projects/lightbox2/images/image-2.jpg")) 
{
    byte[] fileContent = new byte[fileStream.Length];       
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜