Process Images obtained with ImageReader on Android

873 views Asked by At

I am receiving an image from the ImageReader, with format PixelFormat.RGBA_8888

What I want is to transform that image to ARGB.

Get the buffer is simple

private OnImageAvailableListener frameObserver = new OnImageAvailableListener() {
    public void onImageAvailable(ImageReader reader) {
        Image frame = reader.acquireNextImage();
        Image.Plane[] planes = frame.getPlanes();

        ByteBuffer buffer = planes[0].getBuffer();
        byte[] bytes = new byte[buffer.remaining()];
        buffer.get(bytes);

But the results have not sense to me. It is a 320x240 image, it should have 320X240X32(RGBA_8888) bytes... but buffer.length is only 307200 bytes.

It also have striderow 1280 and stridePixel 4, so it should be even bigger.

I know I could be asking a basic question, but unfortunatly I'm ot finding any information or tutorial about this.

Thanks

1

There are 1 answers

0
Jano On

Stupid me, I though RGBA_8888 was 8 bytes per channel, but it is 8 bits (one byte). So each pixel is 4 bytes on the array (not 32).