将Java位图像素传递给jni的最快方法 [英] The fastest way to pass java bitmap pixels to jni

查看:223
本文介绍了将Java位图像素传递给jni的最快方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到将位图从Java传递到JNI的最佳/最快方法.接下来是我目前如何执行此操作.可以改善它,还是有其他更快的方法?

I'm trying to find the best/fastest way to pass a bitmap from java to JNI. Next is how I do this operation at the moment. Can this be improved, or is there any other faster way?

void JNIBitmap::setBuffer(JNIEnv* env, const jobject bitmap)
{
    // Allocate native pixels buffer

    AndroidBitmapInfo bitmapInfo;
    AndroidBitmap_getInfo(env, bitmap, &bitmapInfo)

    this->bufferWidth  = bitmapInfo.width;
    this->bufferHeight = bitmapInfo.height;
    this->bufferSize   = this->bufferWidth * this->bufferHeight * 4;
    this->buffer       = new uint8_t[this->bufferSize];

    // Copy pixels to native buffer

    void* bitmapPixels;
    AndroidBitmap_lockPixels(env, bitmap, &bitmapPixels)

    memcpy((void*)this->buffer, bitmapPixels, this->bufferSize);

    AndroidBitmap_unlockPixels(env, bitmap);
}

推荐答案

最简单的方法是只调用AndroidBitmap_lockPixels. 因此,在JNIBitmap的构造函数中,您可以这样做:

The easiest way is to just call AndroidBitmap_lockPixels. So in the constructor of JNIBitmap you would do this:

void* bitmapPixels;
AndroidBitmap_lockPixels(env, bitmap, &bitmapPixels)

然后在析构函数中执行以下操作:

Then in the destructor you would do this:

AndroidBitmap_unlockPixels( env, bitmap);

这篇关于将Java位图像素传递给jni的最快方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆