如何在Java中将YUV转换为JPG

时间:2019-05-27 06:21:32

标签: java image opencv yuv

有字节数组YUV NV21

如何进行转换并将其保存为jpg文件?

我使用下一个代码

byte[] mYUVData = YUV_420_888toNV21(planeY, planeU, planeV);
Mat mYuv = new Mat(1080 + 1080/2, 1040, CvType.CV_8UC1);
mYuv.put(0, 0, mYUVData);
Mat mRgba = new Mat();
Imgproc.cvtColor( mYuv, mRgba, Imgproc.COLOR_YUV420sp2RGBA );

// Read image as before
MatOfByte mob=new MatOfByte();
Imgcodecs.imencode(".jpg", mYuv, mob);
byte ba[]=mob.toArray();

BufferedImage bi= ImageIO.read(new ByteArrayInputStream(ba));


ImageIO.write(bi, "jpg", new File("C://Users/it/Downloads/image.jpg")); 

But i have wrong jpg image

0 个答案:

没有答案