Extract black and white image from android camera's NV21 format

前端 未结 6 1789
你的背包
你的背包 2020-11-28 02:18

I have done some google-ing around and couldn\'t find enough information about this format. It is the default format for camera preview. Can anyone suggest good sources of i

6条回答
  •  北荒
    北荒 (楼主)
    2020-11-28 02:41

    Here's code to just extract the greyscale image data:

    private int[] decodeGreyscale(byte[] nv21, int width, int height) {
        int pixelCount = width * height;
        int[] out = new int[pixelCount];
        for (int i = 0; i < pixelCount; ++i) {
            int luminance = nv21[i] & 0xFF;
            out[i] = Color.argb(0xFF, luminance, luminance, luminance);
        }
        return out;
    }
    

提交回复
热议问题