问题
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.
Problem: If i have an image greater than 500kb(around), OOME is there saying hello to me.
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.
What i really want is just a hint/logic/architecture which can work on the large image as big as 5 mb....
回答1:
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.
回答2:
try using largeHeap in manifest.xml under application tag add
android:largeHeap = "true"
回答3:
best way to handle really large images is to use JNI .
maybe renderscript can also help, but i'm not sure about its memory limitations.
回答4:
To answer your question, i would consider it in two different parts.
how to avoid out of memory exceptions... you can refer to this link. There is my answer.
Second is if you wanna show image that is as big as 5 MB. You can try having a buffer storage. download image in chunks one by one, save them to temp file and keep clearing the buffer storage. I haven't implemented it myself. you can give it a try.
Thanks: N_JOY
来源:https://stackoverflow.com/questions/8571906/avoiding-out-of-memory-exception-in-applying-filters-to-images-android