我想转换图像从YUV_420_888到RGB和我有一些麻烦输出图像。在我的ImageReader(利用摄像头2 API来获得此图像preVIEW)获得的图像格式YUV_420_888。
i trying convert image from YUV_420_888 to rgb and i have some trouble with output image. In ImageReader i get image in format YUV_420_888 (using camera 2 api for get this image preview).
imageReader = ImageReader.newInstance(1920,1080,ImageFormat.YUV_420_888,10);在为YuvImage类写作Android SDK中,这YuvImage只使用NV21,YUY2。
In android sdk for YuvImage class writing, that YuvImage using only NV21, YUY2.
我们可以看到N21和YUV420之间的区别并不大,我尝试数据转换为N21
as we can see difference between N21 and yuv420 not big and i try convert data to N21
YUV420:
和 N21:
在 onImageAvailable 我得到每个单独的飞机,把他们在正确的位置(如在图片)
in onImageAvailable i get separately each Planes and put them in correct place (as on image)
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ByteBuffer bufferY = image.getPlanes()[0].getBuffer(); byte[] data0 = new byte[bufferY.remaining()]; bufferY.get(data0); ByteBuffer bufferU = image.getPlanes()[1].getBuffer(); byte[] data1 = new byte[bufferU.remaining()]; bufferU.get(data1); ByteBuffer bufferV = image.getPlanes()[2].getBuffer(); byte[] data2 = new byte[bufferV.remaining()]; bufferV.get(data2); ... outputStream.write(data0); for (int i=0;i<bufferV.remaining();i++) { outputStream.write(data1[i]); outputStream.write(data2[i]); }在创建YuvImage,转换为位图,查看和保存
after create YuvImage, convert to Bitmap, view and save
final YuvImage yuvImage = new YuvImage(outputStream.toByteArray(), ImageFormat.NV21, 1920,1080, null); ByteArrayOutputStream outBitmap = new ByteArrayOutputStream(); yuvImagepressToJpeg(new Rect(0, 0,1920, 1080), 95, outBitmap); byte[] imageBytes = outBitmap.toByteArray(); final Bitmap imageBitmap = BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length); mImageView.setImageBitmap(imageBitmap); ... imageBitmappress(Bitmap.CompressFormat.JPEG, 95, out);但我保存的图像是绿色和粉红色:
我错过了什么?
推荐答案有您的转换尝试两个主要问题:
There are two main problems on your conversion attempt:
更多推荐
摄像机2 API YUV420转换为rgb绿了
发布评论