在 iOS 上缩小图像的最节省内存的方法是什么? [英] What is the most memory-efficient way of downscaling images on iOS?

查看:31
本文介绍了在 iOS 上缩小图像的最节省内存的方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在后台线程中,我的应用程序需要从磁盘读取图像,将它们缩小到屏幕大小(1024x768 或 2048x1536)并将它们保存回磁盘.原始图片大多来自相机胶卷,但其中一些可能具有更大的尺寸(例如 3000x3000).

In background thread, my application needs to read images from disk, downscale them to the size of screen (1024x768 or 2048x1536) and save them back to disk. Original images are mostly from the Camera Roll but some of them may have larger sizes (e.g. 3000x3000).

稍后,在另一个线程中,这些图像会经常缩小到 500x500 左右的不同大小并再次保存到磁盘.

Later, in a different thread, these images will frequently get downscaled to different sizes around 500x500 and saved to the disk again.

这让我想知道:在 iOS 中,性能和内存方面最有效的方法是什么?我使用了两种不同的 API:

This leads me to wonder: what is the most efficient way to do this in iOS, performance and memory-wise? I have used two different APIs:

  • using CGImageSource and CGImageSourceCreateThumbnailAtIndex from ImageIO;
  • drawing to CGBitmapContext and saving results to disk with CGImageDestination.

两者都为我工作,但我想知道它们在性能和内存使用方面是否有任何差异.当然,如果有更好的选择.

Both worked for me but I'm wondering if they have any difference in performance and memory usage. And if there are better options, of course.

推荐答案

虽然我不能肯定地说它会有所帮助,但我认为将工作推到 GPU 上是值得的.您可以通过渲染给定大小的带纹理的四边形,或使用 GPUImage 及其调整大小功能来自己完成.虽然它在旧设备上有一些纹理大小限制,但它应该比基于 CPU 的解决方案具有更好的性能

While I can't definetly say it will help, I think it's worth trying to push the work to the GPU. You can either do that yourself by rendering a textured quad at a given size, or by using GPUImage and its resizing capabilities. While it has some texture size limitations on older devices, it should have much better performance than CPU based solution

这篇关于在 iOS 上缩小图像的最节省内存的方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆