0

There are arrays of bytes YUV NV21

How to do the conversion and save it to jpg file?

I use next code

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

lirugo
  • 41
  • 4
  • Check [this SO Post](https://stackoverflow.com/a/45926852/4725875), maybe it will help. – DevilsHnd May 27 '19 at 07:19
  • Thanks, but i use Java SE. I saw that post and they use YuvImage its class only for Android (java.lang.Object ↳ android.graphics.YuvImage) – lirugo May 27 '19 at 07:59

0 Answers0