我有一个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 是我拥有的图像数组。
编辑 Java 代码以将 int[] 转换为图像
像素是我从 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);