将 ciimage 转换为可写格式

发布于 2024-12-18 08:57:49 字数 397 浏览 3 评论 0原文

我需要将 CIImage 转换为可以写入磁盘的格式。

目前我正在使用以下代码将其转换为 JPG 格式。

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

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

但实际内存使用量却高达 100 MB 以上。我的应用程序需要我处理大量图像,因此我需要优化内存使用。

任何人都可以建议什么吗???

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无声静候 2024-12-25 08:57:49

如果是累积内存问题,而不仅仅是一张图像,您可以尝试将最后两行包装在您自己的自动释放池中:

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

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];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文