scorpiozj
scorpiozj

Reputation: 2687

resize image data on iPhone

I get image data from NSURLConnection, and store the data using NSMutableData. The point is that I want to store a smaller size of the image.

Now I use the following code to get a smaller image:


    UIImage *temp = [[UIImage alloc] initWithData: imageData];
    image = [temp resizedImage:CGSizeMake(72, 72) interpolationQuality:kCGInterpolationHigh];
    smallImageData = UIImagePNGRepresentation( image);

My question is can I get smallImageData directly from imageData? As I think my method will cost a lot if I have numbers of connection to get the image data.

Upvotes: 2

Views: 666

Answers (1)

logancautrell
logancautrell

Reputation: 8772

This is a correct method to downsize images. If this is in a tight loop, you can wrap it in an autorelease pool to make sure any temporary objects are collected.

If you are running into issues with memory then serialize your requests to run one at a time.

Upvotes: 2

Related Questions