The image is corrupt or does not contain PNG or JPEG data

Since it does not contain an image, the following line returns an error, how can I control it?
ivReceived.Picture = Picture.FromData(picDoc)

I have the error:
The image is corrupt or does not contain PNG or JPEG data

The important thing is that you get an Exception type UnsupportedFormatException, so you can use Try - Catch to catch those errors and handle them the best that you can (maybe assigning a corrupt image representation).

1 Like

I fixed it with the Try and Catch error As Unsupported FormatException.
And turning off the “Break On Exceptions” from the IDE

if picDoc<>"" then
  Try
    ivReceived.Picture = Picture.FromData(picDoc) 
  Catch err As UnsupportedFormatException
    MessageBox(err.Message)
  End Try
end if

You don’t need (or want) to turn off ‘Break On Exceptions’ as that helps you catch problems before you go to production. Just be aware that the debug will halt on the exception but if you have try-catch just press Resume to continue debugging. Once you are good with your try-catch you can add a pragma to not stop in that part of your program to avoid unnecessary stops while debugging.

@AlbertoD thanks!