最近项目需要用到 opencv 和一些图像引擎处理图像,引擎开放的接口都是处理 nv21 格式的数据。从 Bitmap 出来的都是 argb 格式数据,所以使用的话需要互相转化一下。
Pixels to Nv21
1 | // len(nv21) = len(pixels) * 3 / 2 |
Nv21 to Pixels
1 | void nv21_to_pixels(unsigned char *nv21, unsigned int *pixels, int width, int height) { |
Pixels to Nv21(bytes)
需要这个的原因是,项目有个功能需要接的 api 是用的 camera1 接口出来的 yuv420 数据(byte[] frame)。
1 | byte[] encode_yuv420(int[] argb, int width, int height) { |