By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,775 Members | 1,399 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,775 IT Pros & Developers. It's quick & easy.

Grab png image from web

P: 39
There are images from the web that are PNG's that I am trying to grab. I seem to be able to grab them however when I do they are not the same size (in bytes) as the image that is stored on the web. For instance one image I am trying to grab is 2666 bytes, when I grab it the image become 3190 bytes. I am able to save it on my computer if I just right click it in my web browser and it turns out to be the right number of bytes but how can I do this correctly programmatically?

The function that I am using that does it wrong is
Expand|Select|Wrap|Line Numbers
  1.         private static Image pngFromWeb(string URL)
  2.         {
  3.             WebRequest request = WebRequest.Create(URL);
  5.             WebResponse response = request.GetResponse();
  7.             Image png = Image.FromStream(response.GetResponseStream());
  9.             png.Save("C:\\image.png", System.Drawing.Imaging.ImageFormat.Png);
  11.             response.Close();
  13.             return png;
  14.         }
Dec 16 '08 #1
Share this Question
Share on Google+
2 Replies

Expert 100+
P: 221
Hi There,
Try using WebClient.DownloadFile() instead.
Dec 17 '08 #2

P: 39
Thanks, I found this out like a minute after I posted and it worked nice :-)
Dec 20 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.