I found this on Google, click here, which someone asked a similar question, receiving a response that they should check if their file exists. However, I'm loading images from web links, in which it displays an error image if A)The picture is not found or B)If, like in image hosting services like Photobucket, displays the 'Bandwidth exceeded' image. Is there a way to detect if either an error image is showing or if a image is invalid?
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 could also be a case where the image load completed properly but there was something 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 catches load errors too so might be the one you want to use.
There is no standard way of checking for valid pictures like you would wish to do. The 'Bandwidth exceeded' image is a perfectly valid picture in the eyes of the computer.
Nevertheless you could try some tricks for filtering out at least a few "wrong" images:
You see, those semantic black lists are every thing else than perfect, maybe even worse filter out good images.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With