`
helpbs
  • 浏览: 1162321 次
文章分类
社区版块
存档分类
最新评论

What is JNI Graphics and how to use it?

 
阅读更多

http://stackoverflow.com/questions/5605853/what-is-jni-graphics-or-how-to-use-it



Thejnigraphicslibrary can be used to access bitmap buffers in C/C++ from theandroid.bitmap.Graphicsclass (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 ajobjectto that library so it can give you direct access to a buffer. You can pass that buffer to OpenGL viaglTexImage2D().

First, you need a JavaBitmapobject, 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.


分享到:
评论

相关推荐

    Pro Android C++ with the NDK

    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 ...

    Pro Android Games----精通Android 游戏开发

    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 ...

    Android代码-使用JNI实现Sobel算子图像边缘检测

    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...

    J/Invoke 2010 jinvoke jni 天涯浪子

    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 Programming with OpenCV 3(PACKT,2015)

    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.

    java jni 教程 资料

    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.

    精通Android 4 游戏开发(Advanced.Android.4.Games)

    * 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”...

    sqlite_jni.rar_This Is It

    DO NOT EDIT THIS FILE - it is machine generated.

    JNI编程指南与规范.zip

    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.zip jni编译jni下载

    学习JNI编译时,缺少的jni.h和jni_md.h头文件,Java调用C和C++函数时的JNI使用区别: 注意:jni.h头文件中对于***.c & ***.cpp采用不同的定义

    Apress.Advanced.Android.4.Games.Jan.2012

    * 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

    Aptana studio 安装完启动时中出现Failed to load the JNI shared library如何解决?

    The Java. Native

    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资料大全JNI资料大全JNI资料大全

    DELPHI开发JNI必备 jni.pas

    DELPHI开发JNI必备 jni.pas 包含文件 jni.pas JNI_MD.INC

    Apress.Pro.Android.Games.2Ed.2012

    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实例

    Java jni调用c实例

    JNI++ User Guide

    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的设计思想,对这种思想的理解是使用JNI的各种特性的基础。 本书有一部分是JAVA2平台上面的JNI特征的规范说明。JNI程序员可以把这部分用作一个手册。JVM开发者在实现虚拟机的时候必须遵守这些规范。 ...

    jni.h文件.7z

    jni.h文件jni.h文件jni.h文件jni.h文件jni.h文件jni.h文件

Global site tag (gtag.js) - Google Analytics