简体   繁体   English

将ciimage转换为可写格式

[英]convert ciimage to writable format

I need to convert CIImage to a format which could be written to disk. 我需要将CIImage转换为可以写入磁盘的格式。

Currently I am using the following code to convert it to JPG format . 目前,我正在使用以下代码将其转换为JPG格式。

 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 . 但是实际的内存使用量高达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 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM