Java의 첫 번째 "바이트"는 32 비트가 아니라 8 비트 (부호가있는)입니다. 나는 nio.ByteBufffer를 사용하지 않는다. byte [] 배열이 훨씬 더 간단하고 간단하게 작동합니다. 희망
jboolean Java_jni_AndroidBitmap_updateBitmap(JNIEnv* env, jobject that, jobject bitmap, jbyteArray data, jint w, jint h, jint bpp) {
jbyte* a = (*env)->GetByteArrayElements(env, data, NULL);
jsize bytes = (*env)->GetArrayLength(env, data);
AndroidBitmapInfo info = {0};
int r = AndroidBitmap_getInfo(env, bitmap, &info);
if (r != 0) {
// … "AndroidBitmap_getInfo() failed ! error=%d", r
return false;
}
int width = info.width;
int height = info.height;
if (info.format != ANDROID_BITMAP_FORMAT_RGBA_8888 && info.format != ANDROID_BITMAP_FORMAT_A_8) {
// "Bitmap format is not RGBA_8888 or A_8"
return false;
}
int bytesPerPixel = info.format == ANDROID_BITMAP_FORMAT_RGBA_8888 ? 4 : 1;
void* pixels = null;
r = AndroidBitmap_lockPixels(env, bitmap, &pixels);
if (r != 0) {
// ..."AndroidBitmap_lockPixels() failed ! error=%d", r
return false;
}
if (w == width && h == height && bytesPerPixel == bpp) {
memcpy(pixels, a, width * height * bytesPerPixel);
} else if (bytesPerPixel == 4 && bpp == 1) {
grayscaleToRGBA(pixels, &info, data, w, h);
} else {
assertion(bytesPerPixel == 4 && bpp == 1, "only grayscale -> RGBA is supported bytesPerPixel=%d bpp=%d", bytesPerPixel, bpp);
}
AndroidBitmap_unlockPixels(env, bitmap);
(*env)->ReleaseByteArrayElements(env, data, a, 0);
return true;
}
AndroidBitmap.c
에서 AndroidBitmap.java
public class AndroidBitmap {
public static native void updateBitmap(android.graphics.Bitmap bitmap, byte[] data, int w, int h, int bpp);
}
에서
이 도움이됩니다.
출처
2014-11-02 23:19:59
Leo
네이티브 코드에서 버퍼의 16 진 덤프를 수행하여 픽셀 데이터가 실제로 도착하는지 확인하십시오. – fadden