Bitmap to YUV
来源:互联网 发布:淘宝信誉评级在哪里看 编辑:程序博客网 时间:2024/06/04 20:13
byte [] getNV21(int inputWidth, int inputHeight, Bitmap scaled) { int [] argb = new int[inputWidth * inputHeight]; scaled.getPixels(argb, 0, inputWidth, 0, 0, inputWidth, inputHeight); byte [] yuv = new byte[inputWidth*inputHeight*3/2]; encodeYUV420SP(yuv, argb, inputWidth, inputHeight); scaled.recycle(); return yuv; } void encodeYUV420SP(byte[] yuv420sp, int[] argb, int width, int height) { final int frameSize = width * height; int yIndex = 0; int uvIndex = frameSize; int a, R, G, B, Y, U, V; int index = 0; for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { a = (argb[index] & 0xff000000) >> 24; // a is not used obviously R = (argb[index] & 0xff0000) >> 16; G = (argb[index] & 0xff00) >> 8; B = (argb[index] & 0xff) >> 0; // well known RGB to YUV algorithm Y = ( ( 66 * R + 129 * G + 25 * B + 128) >> 8) + 16; U = ( ( -38 * R - 74 * G + 112 * B + 128) >> 8) + 128; V = ( ( 112 * R - 94 * G - 18 * B + 128) >> 8) + 128; // NV21 has a plane of Y and interleaved planes of VU each sampled by a factor of 2 // meaning for every 4 Y pixels there are 1 V and 1 U. Note the sampling is every other // pixel AND every other scanline. yuv420sp[yIndex++] = (byte) ((Y < 0) ? 0 : ((Y > 255) ? 255 : Y)); if (j % 2 == 0 && index % 2 == 0) { yuv420sp[uvIndex++] = (byte)((V<0) ? 0 : ((V > 255) ? 255 : V)); yuv420sp[uvIndex++] = (byte)((U<0) ? 0 : ((U > 255) ? 255 : U)); } index ++; } } }
0 0
- Bitmap to YUV
- Bitmap和YUV的转换
- Bitmap和YUV的转换
- RGB TO YUV (ZT)
- YUV to RGB Conversion
- YUV to RGB optimization
- Save YUV to Disk
- y4m to YUV
- yuv to rgb
- YUV to RGB Conversion
- test_02:BMP to YUV
- android把YUV数据转成 Bitmap
- rgb to yuv 互相转化
- Bitmap to BitmapSource
- view to bitmap
- ListView To Bitmap
- Drawable to bitmap
- drawable to bitmap
- 布卡直播:看准市场,抓住机会
- OpenCV 立体视觉详细解析(二)---视觉深度测量
- 有向图最短路Dijkstras算法过程动态演示
- sqlite 插入记录注意项
- iOS 学习资料整理
- Bitmap to YUV
- 主机服务规划
- Gabor滤波器学习
- 改造 ztree 以便于兼容 Angular ui-router 的 ui-sref 功能
- [Android] 获取Android设备的唯一识别码|设备号|序号|UUID
- 使用Weka进行数据挖掘
- linux自动创建设备节点
- 字符串处理函数的一些问题
- RadioButton使用注意点