Android NDK如何从Image Array创建Image

时间:2012-11-14 12:48:46

标签: android android-ndk java-native-interface

我在JintArray中有一个JNI。从那我想创建一个图像文件。

现在我正在创建一个图像,方法是将该数组传递给java端,然后将该数组转换为图像。但是在连续使用时看起来很慢。

要创建更多图像,我想在JNI本身中执行该过程。

 jintArray ret = (*env)->NewIntArray(env, pixels);
    (*env)->SetIntArrayRegion(env, ret, 0, pixels, (jint *)pixbuf);
    free(pixbuf);
    LogD("NBridge: Returning data.");
    return ret;

这就是我最后要做的事情。 ret是我正在使用的图像数组。

修改 将int []转换为图像

的Java代码

像素是我从jni获得的int []。

 Bitmap bmp_ss = Bitmap.createBitmap(bitmap_width,
                bitmap_height,
                Bitmap.Config.ARGB_8888);
        bmp_ss.setPixels(pixels, 0, screen_width,
                0, 0, screen_width, screen_height);
 Matrix rotator = new Matrix();
            switch (rotation) {
            case (Surface.ROTATION_0):
                break;
            case (Surface.ROTATION_90):
                rotator.postRotate(0);
                break;
            case (Surface.ROTATION_180):
                rotator.postRotate(180);
                break;
            case (Surface.ROTATION_270):
                rotator.postRotate(0);
                break;


    bmp_ss = Bitmap.createBitmap(bmp_ss, 0, 0, screen_width, screen_height, rotator, false);
try {
                fos = new FileOutputStream(file);
            } catch (FileNotFoundException e) {
                throw new InvalidParameterException();
            }
            bmp_ss.compress(CompressFormat.JPEG, 25, fos);

0 个答案:

没有答案