[RK3288][Android6.0] 调试笔记 --- NV21数据转成JPG

Platform: RK3288
OS: Android 6.0
Kernel: 3.10.92

需要将camera preview callback拿到的NV21数据转换成jpg格式,实现如下:

public void onPreviewFrame(byte[] data, Camera camera) {
    Camera.Size size = mCamera.getParameters().getPreviewSize();
    //Log.i(TAG, "onPreviewFrame: width:"+size.width+" height:"+size.height);
    try{
        YuvImage image = new YuvImage(data, ImageFormat.NV21, size.width, size.height, null);
        if(image!=null){
            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            image.compressToJpeg(new Rect(0, 0, size.width, size.height), 80 ,stream);
            FileOutputStream output = new FileOutputStream("/sdcard/t.jpg");
            output.write(stream.toByteArray());
            output.flush();
            output.close();
            count++;
            Log.i(TAG, "onPreviewFrame: to jpeg");
        }
    } catch (Exception e){

    }
}

参考:
android 调用Camera,获取预览帧中的图像
android-saving-previewcallback-image-as-a-jpg-from-a-byte-array-results-in-a-c

猜你喜欢

转载自blog.csdn.net/kris_fei/article/details/80534169
今日推荐