What is JNI Graphics and how to use it?
来源:互联网 发布:java中json数组的遍历 编辑:程序博客网 时间:2024/05/17 02:46
http://stackoverflow.com/questions/5605853/what-is-jni-graphics-or-how-to-use-it
The jnigraphics
library can be used to access bitmap buffers in C/C++ from theandroid.bitmap.Graphics
class (in Java, of course). It's described in more detail in the documentation that comes with the NDK under:
android-ndk-r5b/docs/STABLE-APIS.html
It can be used to load images for e.g. OpenGL ES in C/C++, but you have to do some work to hand ajobject
to that library so it can give you direct access to a buffer. You can pass that buffer to OpenGL via glTexImage2D()
.
First, you need a Java Bitmap
object, which you can acquire and pass to your native method like this:
import android.graphics.Bitmap;import android.graphics.BitmapFactory; ...BitmapFactory.Options options = new BitmapFactory.Options();options.inScaled = false;Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.myimage, options);MyJniMethod(bitmap); // Should be static in this example
That native method can look something like this:
#include <android/bitmap.h>void MyJniMethod(JNIEnv *env, jobject obj, jobject bitmap) {AndroidBitmapInfo info;uint32_t *pixels;int ret;AndroidBitmap_getInfo(env, bitmap, &info);if(info.format != ANDROID_BITMAP_FORMAT_RGBA_8888) { LOGE("Bitmap format is not RGBA_8888!"); return false;}AndroidBitmap_lockPixels(env, bitmap, reinterpret_cast<void **>(&pixels));// Now you can use the pixel array 'pixels', which is in RGBA format}
Keep in mind you should call AndroidBitmap_unlockPixels()
when you are done with the pixel buffer, and that this example doesn't check for errors at all.
- What is JNI Graphics and how to use it?
- What is reflection and how to use it in CSharp ?
- Introduction to COM - What It Is and How to Use It.(ZT)
- Introduction to COM - What It Is and How to Use It.
- Introduction to COM - What It Is and How to Use It.
- Introduction to COM - What It Is and How to Use It.
- MySpace Unraveled: What it is and how to use it safely
- WHAT IS ISO? A CAMERA’S SENSITIVITY TO LIGHT EXPLAINED, AND HOW TO USE IT
- What is a cronjob and how do I use it?
- Divitis: what it is, and how to cure it
- What is SynchronizationContext, and what does it mean to capture and use it?
- iOS开发KVC——what is about kvc and how to use it ? (总结更新版)
- What is junction object and how to create it?
- What is virtual memory, how is it implemented, and why do operating systems use it?
- What and How to use JSF
- (Page 1 of 3 )A walking tour of JavaBeans What JavaBeans is, how it works, and why you want to use it
- (Page 2 of 3 )A walking tour of JavaBeans 2 :What JavaBeans is, how it works, and why you want to use it
- (Page 3 of 3 )A walking tour of JavaBeans What JavaBeans is, how it works, and why you want to use it
- 常见排序算法:选择排序
- CC2430 Joystick硬件说明
- An error occurred while completing process -java.lang.reflect.InvocationTargetException
- 【问题】$or中的数据作为索引的一些问题
- 编译自己的Windows Android SDK(how to build Android SDK for Windows)
- What is JNI Graphics and how to use it?
- 常见排序算法:归并排序
- HTTP协议详解
- aau和fairy ape模拟精灵的关系
- myeclipse+tomcat中出现org.apache.juli.logging.LogFactory以及ECLIPSE里org.apache.catalina.startup.Bootstrap
- ortp使用详解
- 关于linux 中stat函数的相关参数说明
- Java职业手册
- kettle 转换控件翻译