android/bitmap.h
包含于jnigraphics 库,libjnigraphics.so是android-8新增的一个库,提供对Java中的 bitmap 对象的操作。
链接:
LOCAL_LDLIBS += -ljnigraphics
典型用法:
1 AndroidBitmap_getInfo() 函数从位图句柄(从JNI得到)获得信息(宽度、高度、像素格式)
2 AndroidBitmap_lockPixels() 对像素缓存上锁,即获得该缓存的指针。
3 用C/C++ 对这个缓冲区进行读写
4 用 AndroidBitmap_unlockPixels() 解锁翻译
android-ndk-r9d\platforms\android-19\arch-arm\usr\include\android\bitmap.h
对应的库
android-ndk-r9d\platforms\android-19\arch-arm\usr\lib\libjnigraphics.so
android-ndk-r9d\platforms\android-19\arch-arm\usr\lib\liblog.so
#ifndef ANDROID_BITMAP_H
#define ANDROID_BITMAP_H
#include <stdint.h>
#include <jni.h>
#ifdef __cplusplus
extern "C" {
#endif
#define ANDROID_BITMAP_RESULT_SUCCESS 0
#define ANDROID_BITMAP_RESULT_BAD_PARAMETER -1
#define ANDROID_BITMAP_RESULT_JNI_EXCEPTION -2
#define ANDROID_BITMAP_RESULT_ALLOCATION_FAILED -3
/* Backward compatibility: this macro used to be misspelled. */
/* 宏定义:向后兼容拼写不一致 拼写错误的情况 */
#define ANDROID_BITMAP_RESUT_SUCCESS ANDROID_BITMAP_RESULT_SUCCESS
enum AndroidBitmapFormat {
ANDROID_BITMAP_FORMAT_NONE = 0,
ANDROID_BITMAP_FORMAT_RGBA_8888 = 1,
ANDROID_BITMAP_FORMAT_RGB_565 = 4,
ANDROID_BITMAP_FORMAT_RGBA_4444 = 7,
ANDROID_BITMAP_FORMAT_A_8 = 8,
};
typedef struct {
uint32_t width;
uint32_t height;
uint32_t stride;
int32_t format;
uint32_t flags; // 0 for now
} AndroidBitmapInfo;
/**
* Given a java bitmap object, fill out the AndroidBitmap struct for it.
* If the call fails, the info parameter will be ignored
*
* 接收一个java的bitmap对象 把信息转化到AndroidBitmap结构体中
* 如果调用失败 参数AndroidBitmap结果体将会被略过
*/
int AndroidBitmap_getInfo(JNIEnv* env, jobject jbitmap,
AndroidBitmapInfo* info);
/**
* Given a java bitmap object, attempt to lock the pixel address.
* Locking will ensure that the memory for the pixels will not move
* until the unlockPixels call, and ensure that, if the pixels had been
* previously purged, they will have been restored.
*
* If this call succeeds, it must be balanced by a call to
* AndroidBitmap_unlockPixels, after which time the address of the pixels should
* no longer be used.
*
* If this succeeds, *addrPtr will be set to the pixel address. If the call
* fails, addrPtr will be ignored.
*
*
* 输入一个java的位图对象,尝试锁定像素地址
* 锁定将确保对像素对应的内存不会移动,直到unlockpixels被调用
* 并保证,如果像素被预先清除了,他们将被重新修复
*
* 如果调用成功, 像素所在的内存将不会被使用,直到AndroidBitmap_unlockPixels函数被调用
*
* 如果调用成功 addrPtr指针将会指向像素所在的地址, 如果调用失败,addrPtr指针就被忽略
*
*
*
*/
int AndroidBitmap_lockPixels(JNIEnv* env, jobject jbitmap, void** addrPtr);
/**
* Call this to balanace a successful call to AndroidBitmap_lockPixels
* 对应于 AndroidBitmap_lockPixels 对像素进行解除锁定操作
*/
int AndroidBitmap_unlockPixels(JNIEnv* env, jobject jbitmap);
#ifdef __cplusplus
}
#endif
#endif