Sometimes while working with image, it become necessary to get all the properties of an image. This time, I had to find out all the properties of an Image deployed in a web site.Its interesting- that’s why I wanted to share the small code snippet. For our today’s example – let’s pick this gif from our favorite google.com –
We will find out all the properties from the Image URL.
Something About Bitmap Class of System.Drawing –
It represents the pixel data of the graphics image as GDI+ Bitmap and expose all the attributes related to the Image Graphics. In addition to that, it enables manipulation of the Bitmap and save it as File in different format.
There are many overloaded Constructor in the Bitmap class which enables to create image object in various way at developers convenience.
string url = "http://www.google.com/intl/en_ALL/images/logo.gif"; WebRequest request = WebRequest.Create(url); request.Method = "Get"; WebResponse response = request.GetResponse(); Stream stream = response.GetResponseStream();
And then we can just initialize a Bitmap object with the stream that we have just retrieved from the URL.
Bitmap bitmap = new Bitmap(stream);
We are done. :) We can access all the properties exposed by the Bitmap object representing the Image Graphics –