public static int[] convertByteToColor(byte[] data){ int size = data.length; if (size == 0){ return null; } // 理论上data的长度应该是3的倍数,这里做个兼容 int arg = 0; if (size % 3 != 0){ arg = 1; } int []color = new int[size / 3 + arg]; if (arg == 0){ // 正好是3的倍数 for(int i = 0; i < color.length; ++i){ color[i] = (data[i * 3] << 16 & 0x00FF0000) | (data[i * 3 + 1] << 8 & 0x0000FF00 ) | (data[i * 3 + 2] & 0x000000FF ) | 0xFF000000; } }else{ // 不是3的倍数 for(int i = 0; i < color.length - 1; ++i){ color[i] = (data[i * 3] << 16 & 0x00FF0000) | (data[i * 3 + 1] << 8 & 0x0000FF00 ) | (data[i * 3 + 2] & 0x000000FF ) | 0xFF000000; } color[color.length - 1] = 0xFF000000; // 最后一个像素用黑色填充 } return color; }
RGB转bitmap byteToInt
最新推荐文章于 2022-12-29 16:33:35 发布