Android Camera2 API图像颜色空间 [英] Android Camera2 API Image Color space

查看:171
本文介绍了Android Camera2 API图像颜色空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了

I used this Tutorial to learn and try understand how to make a simple picture taking android app using the Camera2 API. I have added some snippets from the code to see if you all can help me understand some questions I have.

我试图找出图像另存为的方式.是RGB还是BGR?它存储在可变字节中吗?

I am trying to find out how the image is saved as. Is it RGB, or BGR? Is it stored in the variable bytes?

ImageReader reader = ImageReader.newInstance(width,height,ImageFormat.JPEG, 1);


@Override
public void onImageAvailable(ImageReader reader) {
      Image image = null;
      try {
            image = reader.acquireLatestImage();
            ByteBuffer buffer = image.getPlanes()[0].getBuffer();
            byte[] bytes = new byte[buffer.capacity()];
            buffer.get(bytes);
            save(bytes);
      }

推荐答案

以JPEG格式(在第一行中指定)接收图像.Android对JPEG使用YUV(更确切地说是YCbCr)色彩空间.Jpeg大小是可变的,它通过有损压缩进行压缩,并且您几乎无法控制压缩级别.

The image is received in JPEG format (as specified in the first line). Android uses YUV (to be more exact, YCbCr) color space for JPEG. Jpeg size is variable, it is compressed with lossy compression, and you have very little control over the level of compression.

通常,您会在 onImageAvailable() SRGB 像素.该数组的 format ARGB_8888 .您不需要JNI将其转换为BGR,请参见此 answer .

Normally, you receive a JPEG buffer in onImageAvailable() and decode this JPEG to receive a Bitmap. You can get pixels of this Bitmap as an int array of packed SRGB pixels. The format for this array will be ARGB_8888. You don't need JNI to convert it to BGR, see this answer.

您可以从C ++访问Bitmap对象,请参见 ndk/reference/group/bitmap .在那里,您可以找到此位图的像素格式.如果是从JPEG解码的,则应该是 ANDROID_BITMAP_FORMAT_RGBA_8888 .

You can access Bitmap objects from C++, see ndk/reference/group/bitmap. There you can find the pixel format of this bitmap. If it was decoded from JPEG, you should expect this to be ANDROID_BITMAP_FORMAT_RGBA_8888.

这篇关于Android Camera2 API图像颜色空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆