Image Loading in c# from a web URL

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"));

Probably the website is protected against hot linking. Since images are large in size in compare to html pages and websites pays for their used bandwidth, this is a mechanism for protecting websites from bsndwidth theft, by other websites.

The idea is using some kind of authentication and make sure a real user is asking for the image. This is usually done by cookies on the page which contains the image. You need to get those cookies and send them with your request. You need to add a CookieContainer to your request, then request the page the image resides and at the end retrieve the image (use the same request for all steps, cookies would be added and used automatically).


  1. Elisha

    • 2020/3/19

    I'm always a fan of CImg. It's very easy to use. Another user liked the answer as well. I'll post the same example I posted in the answer so 

  2. Hugh

    • 2015/3/8

    I need to read an image file in C/C++. It would be very great, if some one can post the code for me. I work on gray scale images and the images are JPEG. I would like to read the images into a 2D array which will make my work easy.

  3. Sage

    • 2016/8/16

    As a side note, the C code from this article is compatible with any Here I'll show you how to save the above loaded image as PNG and JPG 

  4. Brooks

    • 2017/9/11

    In order to exemplify the usage of the library I’ll demo how to convert an image to gray and how to apply a sepia filter to the image. As a side note, the C code from this article is compatible with any modern C compilers like GCC, Clang and MSVC. You can find the source files and image examples used here on the GitHub repo for this article.

  5. Atreus

    • 2015/5/14

    I need to load still images in JPEG format into a C program and after this i need to run things like edge detection and filtering algorithms. I 

  6. Kase

    • 2020/12/17

    The loading code in this tutorial forces the image to load at 24 bits per pixel, which means it will not have a palette after it gets loaded. If it is required to display images that are between 1 and 8 bits per pixel, the palette must be handled in the painting code as shown in the code example for L_PaintDC .

  7. Anderson

    • 2021/6/10

    Image loading. C. Use the tinyimg_load() function to load an image from disk, for example: int 

  8. Jared

    • 2020/3/4

    Solution 1. You cannot load images in console apps, you need to create a Windows app and use the various Bitmap functions to display images. You could start by adding a simple bitmap to the resources of your project and use LoadImage () [ ^ ]. But you can read them into memory.

  9. Pagano

    • 2016/8/16

    Imago is a simple C library for reading and writing images in many different image file formats. Currently supported file formats: PNG (requires libpng). JPEG ( 

  10. Ulises

    • 2018/6/18

    There are the following functions required for loading and showing an image in OpenCV. Mat: Mat is not a function. It is a data structure, a type of variable. Like int, char, string variable types in C++, Mat is a variable of OpenCV, which creates a matrix data structure to load images inside it. In this program, we wrote 'Mat myImage;'.

  11. Damon

    • 2019/4/19

    In this section, I will show you how to load an image from a file and display the image in a window using OpenCV library functions.

  12. Marcelo

    • 2015/10/13

    @Yam, The code above is from another time. The code does not look like it will work with many images today and then Windows. At 11 years later, you should make a new discussion to ask your question, show your code and tell us the language and what you expected it to do.

  13. Jaxx

    • 2018/8/14

    When dealing with the fact that images get loaded in in a way that they use stb and there is an easy way to load images in upside-down:.

  14. Cannon

    • 2018/5/14

    There is a library that you can use in C language to read and write to Jpeg images. It called jpegLib. Its open source and you can download it from here: libjpeg .

  15. Alexzander

    • 2020/5/10

    I've been creating a game engine for almost a year, and since the start of the development, I have been using stb_image for loading images.

  16. Landry

    • 2017/1/30

    Hello everyone. Im creating a jigsaw puzzle game in C and for that i need to load images into the code..

Comments are closed.

Recent Posts