我可以创建一个使用我在本机代码中创建的 malloced 缓冲区的位图吗?
我有一段本机代码,我正在其中分配(即分配)缓冲区。我喜欢使用 Canvas 绘制操作绘制到该内存中。 但 Canvas 代码使用 Bitmap 作为其支持平面。我想知道是否有一种方法可以用 Android 位图包装本机内存块。
谢谢
视频人
I have a piece of native code where I am mallocing (i.e. allocating) a buffer. I like to draw into this memory using Canvas draw operations.
But Canvas code uses Bitmap as its backing plane. I am wondering if there is a way to wrap native block of memory with Android Bitmap.
Thanks
Videoguy
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以从 JAVA 传递一个 Buffer,用 Native 代码填充它,然后使用 Canvas 渲染它。完成,完美运行。
编辑添加一个示例:
警告,Java 膨胀
,现在是 NDK 端
因此,主要渲染部分在上面的几行中被调用,如上所述,您的缓冲区位于 draw_buffer 结构中。
请检查缓冲技术的传递并通过 JNI 接口跟踪其从 JAVA 到 C 的路径。我小心翼翼地进行了最终的位图渲染操作,没有任何转换 - IMO 最快的方法。
你可以省略帧计数部分,因为我以某种示例为基础,只是想把手放在我得到的新设备上:)
You can pass a Buffer from JAVA, fill it in Native code and then render it using Canvas. Done, works perfectly.
edited to add an example:
warning, Java bloat ahead
and now the NDK side
So the main rendering part is called a few lines above, and as stated, your buffer is located at draw_buffer structure.
Please examine the passing of a buffer technique and trace its path from the JAVA to C via JNI interface. I took care to make a final bitmap rendering operation without any conversions - fastest approach IMO.
You could ommit that frame counting part, as I took some kind of example as a base and just wanted to lay my hands on that new device I got :)
您可以做的是将缓冲区通过 JNI 传递到 java 中,并从中创建一个位图。请参阅此页面。然后你可以使用 Canvas.setBitmap 使其绘制到缓冲区中。
What you could do is pass the buffer through JNI into the java and create a bitmap from it. see this page. Then you can use Canvas.setBitmap to cause it to draw into the buffer.
位图 默认使用本机内存。
Bitmaps use native memory by default.