Question

I need to convert CIImage to a format which could be written to disk.

Currently I am using the following code to convert it to JPG format .

 NSBitmapImageRep* rep = [[[NSBitmapImageRep alloc] initWithCIImage:result] autorelease];

 NSData *JPEGData = [rep representationUsingType:NSJPEGFileType properties:nil];
[JPEGData writeToFile:targetPath atomically:YES]; 

But the real memory usage shoots up to above 100 MB . My application requires me to handle a large number of images so i need to optimise my memory usage.

Can anyone please suggest anything ???

Was it helpful?

Solution

If it's the cumulative memory that's an issue, and not just one image, you can try wrapping the two last lines in your own autorelease pool:

@autoreleasepool {
    NSData *JPEGData = [rep representationUsingType:NSJPEGFileType properties:nil];
    [JPEGData writeToFile:targetPath atomically:YES];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top