public void onPreviewFrame(byte[] data, Camera camera)从摄像头获得的是byte[]数组的RGB565编码数据

解决方案 »

  1.   

    得到的一个RGB565的byte数组,怎么转成图片啊
      

  2.   

    public static Bitmap createBitmap (int[] colors, int offset, int stride, int width, int height, Bitmap.Config config) 
    config选RGB_565 
      

  3.   


    for (int i = 0; i < 153600; i += 2) {
    tmpData = (int) (rgbBuf[i + 1] & 0xff) << 8;
    nextData = (int) (rgbBuf[i] & 0xff);
    sum = tmpData + nextData;
    sum = (sum & 0xffc0) >> 1 | ((char) (sum & 0x001f));
    tmp = intToWord(sum);
    data[i] = tmp[0];
    data[i + 1] = tmp[1];
    }
      

  4.   


    public static byte[] convertRgb2Bmp(byte[] rgbBuf, byte[] header)
    throws Exception {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    try {
    bos.write(header);
    for (int i = 0; i < 153600; i += 2) {
    tmpData = (int) (rgbBuf[i + 1] & 0xff) << 8;
    nextData = (int) (rgbBuf[i] & 0xff);
    sum = tmpData + nextData;
    sum = (sum & 0xffc0) >> 1 | ((char) (sum & 0x001f));
    tmp = intToWord(sum);
    data[i] = tmp[0];
    data[i + 1] = tmp[1];
    }
    bos.write(data);
    bos.flush();
    } catch (Exception ex) {
    ex.printStackTrace();
    throw ex;
    } finally {
    bos.close();
    }
    return bos.toByteArray();
    } public static byte[] formatBMPHeader() throws Exception {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    try {
    bos.write(new byte[] { 'B', 'M' });
    // bos.write(intToDWord(width * height * 2 + 0x36));
    bos.write(intToDWord(320 * 240 * 2 + 0x36));
    bos.write(intToDWord(0));
    bos.write(intToDWord(0x36));
    bos.write(intToDWord(0x28));
    // bos.write(intToDWord(width));
    // bos.write(intToDWord(height));
    bos.write(intToDWord(320));
    bos.write(intToDWord(240));
    bos.write(intToWord(1));
    bos.write(intToWord(16));
    bos.write(intToDWord(0));
    bos.write(intToDWord(0));
    bos.write(intToDWord(0));
    bos.write(intToDWord(0));
    bos.write(intToDWord(0));
    bos.write(intToDWord(0));
    } catch (Exception ex) {
    ex.printStackTrace();
    throw ex;
    } finally {
    bos.close();
    }
    return bos.toByteArray();
    }