I am downloading and saving a radar image (in .gif format) from with web using an NSURLConnection. In the connectionDidFinishLoading: method, I create an image using [UIImage imageWithData:].
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
// Problem is here. mutableData declared earlier.
UIImage *baseImage = [UIImage imageWithData:mutableData];
if (baseImage)
{
// do stuff with image
}
[mutableData release];
}
The problem is that the images I am downloading are sometime blank and have clear background. This is NOT an error in the image (sometimes there is nothing on the radar to return). But when this happens, I am getting this error in the console. The error can also occur when the image has a very small number of pixels (1 or 2).
Error: ImageIO: malformed GIF frame#0 (600 x 550)
When the error occurs, the image that is created is nil. The 600×550 is the size in px of the image I am downloading. So the returned image in nil, which makes it seem as the download has failed.
It is worth noting that baseImage can fail in 2 cases, the one mentioned above or when I download an image that is listed on the server that is not actually there yet. In the second case, mutableData contains an error string. I still need the 2nd case to fail so I know that an image was not successfully downloaded.
What I need to do in this case is actually create the blank image and save it so the user will be able to see that the download performed correctly.
Any ideas?
Thanks,
Ross
Using this code :
I’m afraid I get no errors in the console and a valid UIImage object 🙁
I suppose that you could detect the presence of a string= – i.e. NSSTring stringWithData:encoding: – if it’s a valid string and the image is nil you could probably assume that it’s an error message?