避免内存溢出异常在应用过滤器图像(Android版) [英] Avoiding Out Of Memory Exception in applying filters to Images (Android)

查看:223
本文介绍了避免内存溢出异常在应用过滤器图像(Android版)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想对图像应用一些过滤器。应用的过滤器,我必须先创建一个数组:

I am trying to apply some filters on a Image. To apply the filter, i have to first create an array:

int[] arr = new int[image.width*image.height];// to store each pixel

,然后我可以将它传递到将应用过滤器的功能。

and then i can pass it to the function which will apply the filter.

问题:如果我有超过500KB(约)更大的图像, OOME 有没有说我打招呼。

Problem: If i have an image greater than 500kb(around), OOME is there saying hello to me.

我的尝试:分割完整的图像分为四个部分以及各部分适用于过滤,然后加入他们的行列,但我再次得到了 OOME 在同一条线上,即当创建int数组。

What i tried: Divide the full image into four parts and apply filter on each part and then join them but again i got OOME in the same line, i.e when creating the int array.

我不想妥协的图像质量,缩小它。

I dont want to compromise on the quality of Image and downsize it.

我真正想要的只是一个提示/逻辑/建筑可在大的图像一样大上工作的 5 MB ...

What i really want is just a hint/logic/architecture which can work on the large image as big as 5 mb....

推荐答案

一来处理这个问题的方法是平铺图像,就像你的建议。抓住OOME,并保持你的减半瓷砖的大小,直到数组分配成功。

One way to handle this is to tile the image, like you suggested. Catch the OOME, and keep halving the size of your tiles until the array allocates successfully.

然后每个顺序瓷砖,重新使用阵列每次处理。

Then process each tile sequentially, re-using the array each time.

这篇关于避免内存溢出异常在应用过滤器图像(Android版)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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