位图/帆布用途和NDK [英] Bitmap/Canvas use and the NDK

查看:112
本文介绍了位图/帆布用途和NDK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近发现有没有硬性限制的内存NDK code量能对比分配的内存(25MB〜大多数设备)重数量有限,您可以在Java端分配

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.

我想写的图像处理应用程序(类似于Photoshop中),需要保持一些大位图在内存中,一旦其中,位图数据将采取〜内存20MB。在Java中这样做可以使应用程序容易出在许多设备上存储的例外,我试过了。

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.

我所有的目前的code使用了位图和Canvas类的做我的形象操纵。 任何人都可以提出一些方法,让我分配了我的大部分内存在C面,仍然使用位图+帆布的执行我的绘制操作(使用的是Android 2.1及以上)?

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)?

作为一个例子,如果我的图像是由6位图的层,并且用户绘画第三层上,我需要绘制一个涂料斑点位图的第三层,然后更新屏幕,以显示压扁所有的结果层上彼此顶部的实时性。我认为沿着调用C我的6位图以int数组,并使用该层的副本正在编辑存储在一个位图对象在Java端与画布进行绘画操作的行的东西。我不知道如何扁平化阶段,是去工作,虽然。

As an example, if my image is 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.

推荐答案

查看在NDK的位图等离子的样本。它创建Java中的位图和操作本机code位。一种可行的方法是,你可以分配的内存大块并保持图像的原始code和简单地渲染视图为Java创建位图。该方法渲染视图,并做了扁平化的图像层可能应该在本地code来完成。线沿线的东西:

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(MyDisplayBit​​map);

My_native_render_code(MyDisplayBitmap);

无效();

这篇关于位图/帆布用途和NDK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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