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

查看:110
本文介绍了在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天全站免登陆