iosuiimageviewpngjpegprogressive-download

How do I display a progressive JPEG in an UIImageView while it is being downloaded?


Downloading an image from the net and showing it in an UIImageView is fairly easy. However, this requires the image to be completely downloaded before it is shown to the user, completely defeating progressive JPEG (and PNG) images.

How can I render the partially downloaded images while the transfer is being done? I would imagine the SDK to have some callback function which would update the image, but I can't find such a function. Is it possible at all with the current iOS SDK?


Solution

  • Did you try to render the UIImage partially as didReceiveData gets called … ? Something like …

    -(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
    {
        //TODO: add some error handling in case the image could not be created
        UIImage *img=[UIImage imageWithData:data];
        if (img) {
            self.imageView.image=img;
        }
    }