android camera yuv帧水平翻转实例
2019/7/7 21:55:57
本文主要是介绍android camera yuv帧水平翻转实例,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
Camera预览时需要对yuv帧做水平翻转处理,直接在onPreviewFrame(byte[] data, Camera camera)里调用Mirror函数,处理完后的图片和预览效果成水平翻转关系。
nv21的镜像算法:
private void Mirror(byte[] src, int w, int h) { //src是原始yuv数组 int i; int index; byte temp; int a, b; //mirror y for (i = 0; i < h; i++) { a = i * w; b = (i + 1) * w - 1; while (a < b) { temp = src[a]; src[a] = src[b]; src[b] = temp; a++; b--; } } // mirror u and v index = w * h; for (i = 0; i < h / 2; i++) { a = i * w; b = (i + 1) * w - 2; while (a < b) { temp = src[a + index]; src[a + index] = src[b + index]; src[b + index] = temp; temp = src[a + index + 1]; src[a + index + 1] = src[b + index + 1]; src[b + index + 1] = temp; a+=2; b-=2; } } }
i420的镜像算法:
private void Mirror(byte[] src, int w, int h) { //src是原始yuv数组 int i; int index; byte temp; int a, b; //mirror y for (i = 0; i < h; i++) { a = i * w; b = (i + 1) * w - 1; while (a < b) { temp = src[a]; src[a] = src[b]; src[b] = temp; a++; b--; } } //mirror u index = w * h;//U起始位置 for (i = 0; i < h / 2; i++) { a = i * w / 2; b = (i + 1) * w / 2 - 1; while (a < b) { temp = src[a + index]; src[a + index] = src[b + index]; src[b + index] = temp; a++; b--; } } //mirror v index = w * h / 4 * 5;//V起始位置 for (i = 0; i < h / 2; i++) { a = i * w / 2; b = (i + 1) * w / 2 - 1; while (a < b) { temp = src[a + index]; src[a + index] = src[b + index]; src[b + index] = temp; a++; b--; } }
I420,YV12,NV12,NV21均属于YUV420,以下为四种格式的排列顺序:
I420: YYYYYYYY UUVV =>YUV420P
YV12: YYYYYYYY VVUU =>YUV420P
NV12: YYYYYYYY UVUV =>YUV420SP
NV21: YYYYYYYY VUVU =>YUV420SP
以上这篇android camera yuv帧水平翻转实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持找一找教程网。
这篇关于android camera yuv帧水平翻转实例的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-01-18android.permission.read_media_video
- 2024-01-18android_getaddrinfo failed eai_nodata
- 2024-01-18androidmo
- 2024-01-15Android下三种离屏渲染技术
- 2024-01-09Android 蓝牙使用
- 2024-01-06Android对接华为AI - 文本识别
- 2023-11-15代码安全之代码混淆及加固(Android)
- 2023-11-10简述Android语音播报TTS
- 2023-11-06Android WiFi工具类
- 2023-07-22Android开发未来的出路