Working with URLs

The Working with Streams topic describes how to work with streams and how to send an image from a server to a client. This topic discusses a backward task, namely how to receive an image from a URL on a server.

The idea is quite simple: use an object which can open a System.IO.Stream over the specified URL and pass this stream to an image writer or the Bitmap.Save method. Graphics Mill will download the image and decompress it.

The following code illustrates the idea. It utilizes the static System.Net.WebClient.OpenRead(String) method to open a readable stream for the data downloaded from the specified URL.

Bitmap bitmap = null;
using (var webClient = new System.Net.WebClient())
    using (var stream = webClient.OpenRead(@""))
        bitmap = new Bitmap(stream);