您好,登錄后才能下訂單哦!
Camera預(yù)覽時(shí)需要對(duì)yuv幀做水平翻轉(zhuǎn)處理,直接在onPreviewFrame(byte[] data, Camera camera)里調(diào)用Mirror函數(shù),處理完后的圖片和預(yù)覽效果成水平翻轉(zhuǎn)關(guān)系。
nv21的鏡像算法:
private void Mirror(byte[] src, int w, int h) { //src是原始yuv數(shù)組 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數(shù)組 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幀水平翻轉(zhuǎn)實(shí)例就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持億速云。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。