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.

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top