Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image Loading in c# from a web URL

Tags:

c#

am trying to display an image in a "toolStrip" i c# from a weburl. Am using the following methode to get the image

WebRequest requestPic5 = WebRequest.Create(icon_path);
                         requestPic5.Timeout = 5000;
                         WebResponse responsePic5 = null;
                         Image Myimg5 = null;

if (requestPic5 != null)
   {
      responsePic5 = requestPic5.GetResponse();
      if (responsePic5 != null)
         {
            Myimg5 = Image.FromStream(responsePic5.GetResponseStream());
          }
   }

its failing when Myimg5 = Image.FromStream(responsePic5.GetResponseStream()); throws an exception but the image is still there in the url

But unfortunately most of the time its not loading properly and sometimes throwing a 404 error

like image 382
raki Avatar asked Oct 02 '09 13:10

raki


People also ask

Can we do image processing in C?

It should compile fine using commercially available C/C++ compilers. The software works on 8-bit, gray scale images in TIFF and BMP file formats. Inexpensive programs are available to convert almost any image into one of these formats. Chapter 0 introduces the C Image Processing System.

What is Stb_image?

// stb_image supports loading HDR images in general, and currently the Radiance. // .HDR file format specifically. You can still load any file through the existing. // interface; if you attempt to load an HDR file, it will be automatically remapped.

What is Stbi_load?

Function stbi_load returns a pointer to an unsigned char* buffer. The size of this buffer is width * height * channels . The image data is stored in the buffer in row order, i.e., the first width * channels bytes belong to the first row of image. The following code sets the first 10 rows of the input image to black.


1 Answers

The response stream has other stuff that you don't necessarily want. You really just want the raw data of the imgage file, so you can use:

new MemoryStream(new WebClient().DownloadData("http://address/file.ico"));

like image 102
danielpops Avatar answered Oct 17 '22 18:10

danielpops