I have a painting application that is running out of memory on a few devices really quick... :(
The problem is that I have bitmaps that are screen size and I'm loading 2 or 3 images to memory than I create a blank bitmap attached to a canvas for merging the 3 images into it. So yeah lot of bitmaps...
My goal is to use the NDK to load the images from file merge them and return only one Bitmap. Well essentially in java I would create the empty image and pass the object to the NDK. This should alleviate the amount of memory used on the device. At least in theory...
The first problem I'm facing is decoding the png image from file. How can I do this via NDK? Should I use BitmapFactory via JNI?
Than the bigger question how do I merge these ARGB bitmaps?
I am not familiar with what image manipulation abilities are built into the NDK, but the OpenCV library can be included for use in the native code, and that is what I use (largely due to previous familiarity, but it is really nice).
Here's the OpenCV 4 Android project. Here is how you would open a PNG.
Related
In my android app,I am displaying various images from gallery whose paths are stored in a database and on runtime it uses bitmap to display image from these paths and due to this it is consuming lot of memory.It is crashing in many mobiles although I am reducing the quality of image. Is there any other way to do this?
I'd strongly suggest looking into image libraries such as Picasso and Glide. Displaying bitmaps natively in Android requires a fair amount of coding to ensure issues like Outofmemory error do not occur.
I have seen a lot of developer use all asset or images or drawable needed into one file png like this :
the question is how can developer split each image to use it in android ?
and what's advantage of this technique ?
This technique is mainly used in game development, and the file you linked is called a Texture Atlas.
It's main advantage is that the game engine has to load only one texture which saves a lot of memory writing, making the game run smoother.
Splitting is normally done with the help of an XML/JSON file which contains the coordinates and size of every image, that way the engine knows where each image is located in the atlas.
You can find more information about Texture Atlases here
I am new to using Pygame for Android and I have been trying to convert my This Game to an android game. Here I need to load around 6 images in one screen but when I try to load more than two images, the apk-application closes down abruptly (it works fine on PC). Here is the complete code of what I have done so far.
Is there any way I can load multiple images without making the game unstable for android?
Note : I am using Pygame Subset for Android to convert my .py to .apk
Yes you can, use Picasso library for loading the images. I had the same problem with OutOfMemory exceptions, but this library solved my problem.
Download the Jar file and include it to your project, but before that make sure you read the documentation, it's very short and simple especially the IMAGE TRANSFORMATION part.
My application has an activity with metro schema, so for good quality I need to put image with resolution more then 2000x2000, but such images use much memory and application crashes with Out of memory error.
Does this problem will solve when I will change the image source to SVG (by svg-android for example)?
It depends on the complexity of image simple vector re presentable image will defiantly improve the performance otherwise complex images will use more memory.
more Details here.
I am writing a program to manipulate images,ie change its color,brightness,contrast etc...
The DVM doesn't support the manipulation of images of size beyond a limit...Can any one tell me whether using Open CV will solve the issue(as this seems to be a better option than NDK)?
Or will I have to use NDK?
I have done a lot of search and was not able to find answer..
First of all, there are different options for Image processing in Android, see here for a comparison of the most popular options: see Android Computer Vision JavaCV OpenCV FastCV comparison and Image processing library for Android and Java
Coming back to your question: If the images you deal are really very large so that they do not fit into the memory of the device, you need to process the images in small chunks called tiles.
If your images are not that big, I recommend you to use OpenCv, if you have to do anything more than very simple tasks such as brightness/contrast adjustment.