C jni-使用bitmap.h提取像素,并将其存储在不工作的3D数组中

C jni-使用bitmap.h提取像素,并将其存储在不工作的3D数组中,c,image-processing,bitmap,java-native-interface,native,C,Image Processing,Bitmap,Java Native Interface,Native,我想把一个位图传给native,在bitmap.h的帮助下提取像素,然后将像素存储在3D数组中(x和y以及颜色通道),通过调用其他c函数对数组进行一些处理,完成后,我将数组写回位图的像素。问题是:我可以提取像素,但不能将它们存储在数组中。另外,如果你能告诉我如何写回数组位图的像素 我的c代码是: #include <jni.h> #include <time.h> #include <android/log.h> #include <android/bi

我想把一个位图传给native,在bitmap.h的帮助下提取像素,然后将像素存储在3D数组中(x和y以及颜色通道),通过调用其他c函数对数组进行一些处理,完成后,我将数组写回位图的像素。问题是:我可以提取像素,但不能将它们存储在数组中。另外,如果你能告诉我如何写回数组位图的像素

我的c代码是:

#include <jni.h>
#include <time.h>
#include <android/log.h>
#include <android/bitmap.h>

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define  LOG_TAG    "libimageprocessing"
#define  LOGI(...)  __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
#define  LOGE(...)  __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)

static void process(AndroidBitmapInfo* info, void* pixels){
    int xx, yy, red, green, blue;
    int w = info->width;
    int h = info->height;
    uint32_t* line;
    int rgb[h][w][3];
    for(yy = 0; yy < info->height; yy++){
            line = (uint32_t*)pixels;
            for(xx =0; xx < info->width; xx++){

                red =  (int) ((line[xx] & 0x00FF0000) >> 16);
                green = (int)((line[xx] & 0x0000FF00) >> 8);
                blue = (int) (line[xx] & 0x00000FF );

        red = 255 - red;
        green = 255 - green;
        blue = 255 - blue ;

        rgb[yy][xx][0] = red; ////THIS LINE CAUSES THE CRASH, If removed the app returns the inverted image. I WANT TO IMPLEMENT SUCH THING, THEN I DON'T KNOW HOW TO WRITE IT BACK TO BITMAP PIXELS.



        line[xx] =
          ((red << 16) & 0x00FF0000) |
          ((green << 8) & 0x0000FF00) |
          (blue & 0x000000FF);
            }

            pixels = (char*)pixels + info->stride;
        }
}


JNIEXPORT void JNICALL Java_com_example_ibm_MainActivity_process(JNIEnv* env, jobject  obj, jobject bitmap)
{
     AndroidBitmapInfo  info;
        int ret;
        void* pixels;

        if ((ret = AndroidBitmap_getInfo(env, bitmap, &info)) < 0) {
                LOGE("AndroidBitmap_getInfo() failed ! error=%d", ret);
                return;
            }
        if (info.format != ANDROID_BITMAP_FORMAT_RGBA_8888) {
            LOGE("Bitmap format is not RGBA_8888 !");
            return;
        }

        if ((ret = AndroidBitmap_lockPixels(env, bitmap, &pixels)) < 0) {
            LOGE("AndroidBitmap_lockPixels() failed ! error=%d", ret);
        }
        process(&info,pixels);

        AndroidBitmap_unlockPixels(env, bitmap);
}
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#定义日志标签“libimageprocessing”
#定义LOGI(…)\uuuuuAndroid\uLog\uPrint(android\uLog\uInfo、log\uTag、VA\uArgs\uuuu)
#定义日志(…)\uuuuuAndroid\uLog\uPrint(android\uLog\uError,log\uTag,\uuuU VA\uArgs\uuuuu)
静态无效进程(AndroidBitmapInfo*信息,无效*像素){
int xx,yy,红色,绿色,蓝色;
int w=信息->宽度;
int h=信息->高度;
uint32_t*线;
国际rgb[h][w][3];
用于(yy=0;yyheight;yy++){
行=(uint32_t*)像素;
对于(xx=0;xxwidth;xx++){
红色=(int)((第[xx]行和0x00FF0000)行>>16);
绿色=(int)((第[xx]行和0x0000FF00)行>>8);
蓝色=(int)(第[xx]行和第0x00000FF行);
红色=255-红色;
绿色=255-绿色;
蓝色=255-蓝色;
rgb[yy][xx][0]=red;///这一行会导致崩溃,如果删除,应用程序会返回反转图像。我想实现这样的事情,那么我不知道如何将其写回位图像素。
第[xx]行=

((红色
rgb
只是一个指针。你在哪里为数组分配空间?忘记了
malloc
?三星程序员不是一种恭维,你会用
uint32\u t***rgb做什么;
你知道这是在声明一个指向
uint32
指针的指针数组,也许你想要一个
char数组e> ?我编辑了使用rgb[][]的代码。同样的事情。位图有多大?它可能太大,无法在堆栈上创建数组,导致堆栈溢出。使用动态内存创建位图大约需要2000*1500@samgakTry,可能您遇到了…堆栈溢出