I'm grabbing an image from an IP camera like so:
Dim http as new HTTPSocket
Dim mPhoto as string
Dim feed as Picture
mPhoto = http.get("http://192.168.200.80/cgi-bin/viewer/video.jpg",1)
if mPhoto <> "" then
feed = StringtoPictureMBS(mPhoto,"mypicture.jpg","Image/jpeg")
if feed <> nil then return feed
end if
return nil
Which works fine if the camera returns a complete JPEG file.
Occasionally an image may not be received in its entirety because we either didn't wait long
enough or because the camera dropped the connection mid stream.
The problem arises in that StringtoPictureMBS still returns a Picture even if its incomplete.
This then throws an exception if I try to access the Graphics portion of the picture to draw
to it (I'm adding text). How can I tell whether the picture is valid or not?
I can send this invalid picture on to a client connecting to my application via HTTP and the
clients browser displays the image (albeit incomplete).
I'm working around the problem by recreating the image using this
feed = feed.ScaleMBS (feed.Width,feed.height,false)
It would be nice if StringtoPictureMBS returned a boolean that told me whether it was valid or not,
or if when it returned a Picture it did its own stuff to make it valid - an invalid picture will still
have an image in it that at least on Mac OS I'm able to view the parts that are valid.
Below is an example of an incomplete picture sent from my IP camera:
