Introduction to Git Basics
View more presentations from Roy Lee.
HelloWorld.javaCompile the JAVA class -- HelloWorld.class
class HelloWorld { private native void print(); public static void main(String[] args) { new HelloWorld().print(); } static { System.loadLibrary("HelloWorld"); } }
Generate the NATIVE header file -- HelloWorld.h$ javac HelloWorld.java
$ javah -jni HelloWorld
HelloWorld.hImplement the NATIVE method -- HelloWorld.c
/* DO NOT EDIT THIS FILE - it is machine generated */ #include <jni.h> /* Header for class HelloWorld */ #ifndef _Included_HelloWorld #define _Included_HelloWorld #ifdef __cplusplus extern "C" { #endif /* * Class: HelloWorld * Method: print * Signature: ()V */ JNIEXPORT void JNICALL Java_HelloWorld_print (JNIEnv *, jobject); #ifdef __cplusplus } #endif #endif
HelloWorld.cCompile the NATIVE source code and build the NATIVE library
#include <stdio.h> #include <jni.h> #include "HelloWorld.h" JNIEXPORT void JNICALL Java_HelloWorld_print (JNIEnv *env, jobject obj) { printf("Hello World\n"); return; }
Add "current" directory to the search path of share libraries$ gcc -c -fPIC HelloWorld.c -I$JAVA_HOME/include -I$JAVA_HOME/include/linux $ gcc -shared HelloWorld.o -o libHelloWorld.so
Run the HelloWorld JAVA program$ export LD_LIBRARY_PATH=.
$ java HelloWorld
Hello World
The dumped raw data is in RGB565 pixel format. So we'd like to convert it into a more common image format that could be recognized by common image viewers.$ adb pull /dev/graphics/fb0 fb.dump
In this case, more than one images might be generated and named output1.png, output2.png, etc. This happens because the framebuffer on android is required to support page flipping, and the backed buffer can be dumped from the /dev/graphics/fb0 as well.$ ffmpeg -f rawvideo -pix_fmt rgb565 -s 320x480 -i fb.dump output%d.png
Here we explicitly specify the width, height(x2 for the backed buffer), and color depth. In this case, we get a single image which is composed by two cascaded snapshots.$ fbgrab -f fb.dump -w 320 -h 960 -b 16 output.png
However, the only benefit with this, I think, is saving some time to type the dimension of the framebuffer, since the fbgrab would figure it out with IOCTL on the device node.$ fbgrab -d /dev/graphics/fb0 output.png