/ Published in: C#
This snippet pulls down an image from a URL into a byte(). From there you can re-size or save.
Don't forget the necessary try - catch.
Don't forget the necessary try - catch.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
public byte[] getImageFromUrl(string url) { System.Net.HttpWebRequest request = null; System.Net.HttpWebResponse response = null; byte[] b = null; request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url); response = (System.Net.HttpWebResponse)request.GetResponse(); if (request.HaveResponse) { if (response.StatusCode == System.Net.HttpStatusCode.OK) { Stream receiveStream = response.GetResponseStream(); { b = br.ReadBytes(500000); br.Close(); } } } return b; }