문제

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 ???

도움이 되었습니까?

해결책

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];
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top