bitmap转byte[]裸数据,并把ARGB_8888转化成RGB_565

public byte[] bitmap2RGB(Bitmap bitmap) {

        if (bitmap == null) {

            return null;
        }

        bitmap.getPixels(bitmap_data, 0, width, 0, 0, width, height);

        for (int i = 0; i < width * height; i++) {

            short rgb565 = (short) RGB888ToRGB565(bitmap_data[i]);

            shortToByteArray1(rgb565, screenByte, i * 2);
        }

        return screenByte;
    }

    public static int shortToByteArray1(short i, byte[] data, int offset) {
        data[offset + 1] = (byte) (i >> 8 & 255);
        data[offset] = (byte) (i & 255);
        return offset + 2;
    }

    public static int RGB888ToRGB565(int rgb8888) {
        return (rgb8888 >> 19 & 31) << 11 | (rgb8888 >> 10 & 63) << 5 | rgb8888 >> 3 & 31;
    }


测试方法耗时47~70ms

你可能感兴趣的:(bitmap转byte[]裸数据,并把ARGB_8888转化成RGB_565)