常見圖片數(shù)據(jù)處理

常見圖片處理

1. RGB轉(zhuǎn)RGBA

rgb數(shù)據(jù)轉(zhuǎn)成rgba數(shù)據(jù),在rgb的基礎(chǔ)上新增alpha通道
    private byte[] rgb2Rgba(byte[] rgb) {
        byte[] rgba = new byte[width * height * 4];
        int count =rgb.length/3;
        for(int i=0;i<count;i++) {
            rgba[i*4+0] =rgb[i*3+0];
            rgba[i*4+1] =rgb[i*3+1];
            rgba[i*4+2] =rgb[i*3+2];
            rgba[i*4+3] =1;
        }

        return rgba;
    }

2. RGBA轉(zhuǎn)RGB

rgba數(shù)據(jù)轉(zhuǎn)成rgb數(shù)據(jù),在rgba的基礎(chǔ)上去除alpha通道
    private byte[] rgba2Rgb(byte[] rgba) {
        byte[] rgb  = new byte[width * height * 3];
        int count =rgb.length/3;
        for(int i=0;i<count;i++) {
           rgb[i*3+0]  =rgba[i*4+0];
            rgb[i*3+1] =rgba[i*4+1];
            rgb[i*3+2] =rgba[i*4+2];
        }

        return rgb  ;
    }

3. RGB轉(zhuǎn)BGR

rgb 數(shù)據(jù)轉(zhuǎn)成bgr數(shù)據(jù),在rgb的基礎(chǔ)上將r和b通道互換
    private byte[] rgb2bgr(byte[] rgb) {
        byte[] bgr  = new byte[width * height * 3];
        int count =bgr.length/3;
        for(int i=0;i<count;i++) {
            bgr[i*3+0]  =rgb[i*3+0];
            bgr[i*3+1] =rgb[i*3+1];
            bgr[i*3+2] =rgb[i*3+2];
        }

        return bgr;
    }
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容