Detecting when image error is used in PictureBox

I found this on Google, click here , someone asked a similar question, getting the answer that they should check if their file exists. However, I do download images from web links that display an error image if A) No image was found or B) If, for example, image hosting services such as Photobucket display an image with excess bandwidth. Is there a way to determine if the image is displayed erroneously or if the image is invalid?

+6
c # image picturebox
source share
2 answers

Yes, the LoadCompleted event tells you what went wrong:

private void pictureBox1_LoadCompleted(object sender, AsyncCompletedEventArgs e) { if (e.Error != null) { // You got the Error image, e.Error tells you why } } 

There may also be a case where the image was loaded correctly, but something was wrong with the image file itself:

 private void pictureBox1_Paint(object sender, PaintEventArgs e) { if (pictureBox1.Image == pictureBox1.ErrorImage) { // You got the Error image } } 

This event handler also causes boot errors, so there may be one that you want to use.

+9
source share

There is no standard way to check the correct images, as you would like to do. Exceeding the bandwidth is an absolutely correct image in the eyes of a computer.

However, you could try some tricks to filter at least a few "wrong" images:

  • If you upload images, set up a web connection that does not perform automatic redirects. You can create some kind of semantics that categorizes the image as "invalid" if you are redirected to another place where the "image with excess bandwidth" is possible. The disadvantage of this method, of course, is that you are possibly filtering the images that are behind the redirect and which are valid.
  • Just check the name of the image submitted by the web server. If you connect to an address, for example, " http: //test.tld/image.jpg ", but when you receive "bandwidth_exceeded.jpg" or something similar, this should be clear. This method requires you to know how the image host image is called their "bandwidth" or "more inaccessible" images.
  • Some verification of image recognition against known "bad" images. Pretty complicated.

You see that these semantic blacklists are anything but perfection, it may even be worse to filter out good images.

+1
source share

All Articles