开发者

Bitmap/Canvas use and the NDK

开发者 https://www.devze.com 2023-02-07 05:54 出处:网络
I\'ve recently found out that there is no hard limit to the amount of memory NDK code can allocate in contrast to the heavily limited amount of memory (~25Mb on most devices) you can allocate on the J

I've recently found out that there is no hard limit to the amount of memory NDK code can allocate in contrast to the heavily limited amount of memory (~25Mb on most devices) you can allocate on the Java side.

I want to write an image processing app (something like Photoshop) that needs to keep several large bitmaps in memory at once where the bitmap data will take ~20Mb of memory. Doing this in Java makes the app prone to out of memory exceptions on many devices I've tried.

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

As an example, if my image i开发者_开发问答s composed of 6 bitmap layers and the user is painting on the 3rd layer, I need to draw a paint blob bitmap to the 3rd layer and then update the screen to show the result of flattening all layers on top of each other in real time. I've considered something along the lines of allocating my 6 bitmaps in C as int arrays and performing the painting operation on the Java side with Canvas using a copy of the layer being edited stored in a Bitmap object. I'm not sure how the flattening stage is going to work though.


Check out the "bitmap-plasma" sample in the NDK. It creates a bitmap in Java and manipulates the bits in native code. One possible technique is that you can allocate the large blocks of memory and hold your images in native code and simply render a "view" into a Java-created bitmap. The method to render the view and do the "flattening" of your image layers should probably be done in native code. Something along the lines of:

...user changed a layer...

My_native_render_code(MyDisplayBitmap);

invalidate();

0

精彩评论

暂无评论...
验证码 换一张
取 消