编辑:解决了!见下文。我需要裁剪从 Camera2 的 onImageAvailable 侦听器获取的图像(YUV422888 颜色空间)。我不想或不需要将其转换为位图,因为它对性能影响很大,而且我实际上对亮度感兴趣,而不是对 RGB 信息(包含在图像的平面 0 中)感兴趣。我想出了以下解决方案:
不幸的是,第 4 点产生了损坏的图像。我究竟做错了什么?
在Camera2的onImageAvailableListener中(请注意,虽然我正在计算位图,但这只是为了看看发生了什么,因为我对位图/RGB数据不感兴趣):
Image.Plane[] planes = image.getPlanes();
ByteBuffer buffer = planes[0].getBuffer(); // Grab just the Y' Plane.
buffer.rewind();
byte[] data = new byte[buffer.capacity()];
buffer.get(data);
Bitmap bitmap = cropByteArray(data, image.getWidth(), image.getHeight()); // Just …Run Code Online (Sandbox Code Playgroud)