3、 Jpeg quality参数的获取
在文件CameraProfile.java中,有下面的code:
static {
System.loadLibrary("media_jni");
native_init();
sJpegEncodingQualityParameters = getImageEncodingQualityLevels();
}
private static int[] getImageEncodingQualityLevels() {
int nLevels = native_get_num_image_encoding_quality_levels();
if (nLevels != QUALITY_HIGH + 1) {
throw new RuntimeException("Unexpected Jpeg encoding quality levels " + nLevels);
}
int[] levels = new int[nLevels];
for (int i = 0; i < nLevels; ++i) {
levels[i] = native_get_image_encoding_quality_level(i);
}
Arrays.sort(levels); // Lower quality level ALWAYS comes before higher one
return levels;
}
// Methods implemented by JNI
private static native final void native_init();
private static native final int native_get_num_image_encoding_quality_levels();
private static native final int native_get_image_encoding_quality_level(int index);
}
存储jpeg quality参数的数组sJpegEncodingQualityParameters由函数
getImageEncodingQualityLevels()产生,在该函数中调用了JNI接口
native_get_num_image_encoding_quality_levels()获取了quality等级的数目,然后又通过native_get_image_encoding_quality_level(i)获取每个等级对应的值,并通过Arrays.sort(levels)对这些值进行了排序,最好返回给数组
sJpegEncodingQualityParameters。
这里动态加载了库media_jni,并且调用了三个JNI接口,下面我们对JNI层的相关code做以介绍。