Bitmap

private Bitmap byte2Bmp(byte[] imgByte) {
        // 2608 x 1960 = 5111680 pixel
        // 652 x 490 = 319480 pixel
        int display_width = 2608;
        int display_height = 1960;

        int[] imgInt = new int[display_width * display_height];
        for(int i = 0; i < display_width * display_height; i++) {
            //Big-Endian
            imgInt[i] = imgByte[1+2*i] & 0xFF |
                    (imgByte[2*i] & 0xFF) << 8 |
                    0x00 << 16 |
                    0xFF << 24;
            //Little-Endian
//                imgInt[i] = imgByte[2*i] & 0xFF |
//                        (imgByte[1+2*i] & 0xFF) << 8 |
//                        0x00 << 16 |
//                        0xFF << 24;
        }

        // Test
        //Log.e(TAG, " byte2Bmp imgInt.size: " + imgInt.length);
        Bitmap bitmap1 = Bitmap.createBitmap(display_width, display_height, Bitmap.Config.ARGB_8888);
        bitmap1.setPixels(imgInt, 0, display_width, 0, 0, display_width, display_height);

        //Log.e(TAG, " byte2Bmp bitmap1.width: " + bitmap1.getWidth() + "bitmap1.height: " + bitmap1.getHeight());
        // 2608 x 1960 = 5111680
        //short[] dstBuf = new short[5111680];
        //img.getPlanes()[0].getBuffer().order(ByteOrder.nativeOrder()).asShortBuffer().get(dstBuf);
        return bitmap1;

    }

byte转bitmap

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值