0

I am trying to download images (jpg, jpeg and png). But when the size exceeds 200,000 bytes, I'm getting a black and white picture.

My code:

byte[] fileBytes;
try 
{ 
   path = url + path; 
   fileBytes = (new WebClient()).DownloadData(path); 
}
catch
{
   path = urlNoimagefound;
   fileBytes = (new WebClient()).DownloadData(path);
}
... 
// and then I add byte in rdlc

I think I'm getting a black and white picture because of the size of the byte array.

How to fix that?

Thank you.

Puthxii
  • 47
  • 9

1 Answers1

0

I am not sure how to do with DownloadData, but here is a snippet I use in an old project:

private static Image DownloadImage(string source)
{
    using (var webClient = new WebClient())
    using (var stream = webClient.OpenRead(source))
    {
        return Image.FromStream(stream);
    }
}
aloisdg
  • 22,270
  • 6
  • 85
  • 105