Using Bitmap / Canvas and NDK

I recently learned that there is no hard limit on the amount of memory that NDK code can allocate in contrast to the very limited amount of memory (~ 25 MB on most devices) that you can allocate on the Java side.

I want to write an image processing application (something like Photoshop), which should contain several large bitmap images in memory at once, where bitmap data will occupy ~ 20 MB of memory. Doing this in Java makes the application prone to memory exceptions on many devices that I have tried.

All of my current code uses the Bitmap and Canvas class to do my image manipulations. Can someone suggest some way that allows me to allocate most of my memory on the C side and still use Bitmap + Canvas to do my drawing operations (using Android 2.1 and above)?

As an example, if my image consists of 6 raster layers and the user draws at level 3, I need to draw a red-red raster image at level 3, and then refresh the screen to show the result of smoothing all the layers on each friend in real time. I looked at something along the line of highlighting my 6 bitmaps in C as int arrays and performing a drawing operation on the Java side using Canvas using a copy of the editable layer stored in the Bitmap object. I'm not sure how flattening will work.

+1
java c android android-ndk
source share
1 answer

Check out the sample bitmap plasma in the NDK. It creates a bitmap in Java and manages the bits in native code. One possible way is that you can allocate large blocks of memory and hold images in your own code and simply render the โ€œviewโ€ in a bitmap file created by Java. The method of rendering visualization and โ€œsmoothingโ€ your image layers should probably be done in native code. Something like:

... user changed layer ...

My_native_render_code (MyDisplayBitmap);

Invalidate ();

+3
source share

All Articles