http://stackoverflow.com/questions/5605853/what-is-jni-graphics-or-how-to-use-it
Thejnigraphics
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 viaglTexImage2D()
.
First, you need a JavaBitmap
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 callAndroidBitmap_unlockPixels()
when
you are done with the pixel buffer, and that this example doesn't check for errors at all.
分享到:
相关推荐
How to use Java Native Interface (JNI) to connect native code to Java world. Auto-generate JNI code using Simplified Wrapper and Interface Generator (SWIG). Introduction to Bionic API Networking ...
Enjoy What you'll learn How to write/port advanced 3D games for any Android device Details on installing the development software, including tool chain compilers and IDEs, and setting up the overall ...
Sand is Android library that it is using JNI to achieve Sobel operator image edge detection. it's easy to build a picture like sand . 中文文档Screenshot Build Step 1. Add the JitPack repository to...
Unlike error-prone JNI programming that is hard to use and deploy, J/Invoke lets you access native libraries by simply declaring native methods, and calling them from pure Java. Java programmers can ...
Android Application ... Although it focuses on OpenCV's Java bindings, this edition adds an extensive chapter on JNI and C++, so that the reader is well primed to use OpenCV in other environments.
This chapter introduces the Java Native Interface (JNI).... Programmers can write one version of a native application or library and expect it to work with all Java VMs supporting the JNI.
* How to use Bluetooth controllers (Zeemote) * More gaming tricks and tips, such as hybrid 3D graphics with OpenGL and JNI * How to port and augment a 2D shooter game app similar to “Wolfenstein”...
DO NOT EDIT THIS FILE - it is machine generated.
JNI程序员指南与规范.pdf + 06 JNI编程指南.pdf NDK开发汇总 ... THIS book covers the Java™ Native Interface (JNI). It will be useful to...how to handle features such as garbage collection and multithreading
学习JNI编译时,缺少的jni.h和jni_md.h头文件,Java调用C和C++函数时的JNI使用区别: 注意:jni.h头文件中对于***.c & ***.cpp采用不同的定义
* How to use Bluetooth controllers (Zeemote) * More gaming tricks and tips, such as hybrid 3D graphics with OpenGL and JNI * How to port and augment a 2D shooter game app similar to “Wolfenstein”...
Aptana studio 安装完启动时中出现Failed to load the JNI shared library如何解决?
helpful tips on how to use the JNI effectively. The JNI was initially released in early 1997. The book summarizes two years of collective experience gained by engineers at Sun Microsystems as well as ...
JNI资料大全JNI资料大全JNI资料大全JNI资料大全JNI资料大全JNI资料大全JNI资料大全JNI资料大全JNI资料大全
DELPHI开发JNI必备 jni.pas 包含文件 jni.pas JNI_MD.INC
More gaming tricks and tips, such as hybrid 3D graphics with OpenGL and JNI How to port, augment a 3D shooter "Doom"-like game app using OpenGL How to build a 3D shooter game like "Quake" and "Quake ...
Java jni调用c实例
JNI++ User Guide.pdf JNI++ is a set of code generating utilities designed to minimize the amount of time required to map between the worlds of C++ and Java.
本书介绍了JNI的设计思想,对这种思想的理解是使用JNI的各种特性的基础。 本书有一部分是JAVA2平台上面的JNI特征的规范说明。JNI程序员可以把这部分用作一个手册。JVM开发者在实现虚拟机的时候必须遵守这些规范。 ...
jni.h文件jni.h文件jni.h文件jni.h文件jni.h文件jni.h文件