2013年8月26日星期一

Android Find RGB565 byte array composed picture java code oralgorithms

public void onPreviewFrame (byte [] data, Camera camera)

is obtained from the camera byte [] array RGB565 encoded data

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

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];
}

------ reference ---------------------- -----------------
nobody know
------ reference ---------------- -----------------------
get an RGB565 byte array , how turn into a picture ah
------ reference - --------------------------------------
  This reply was moderator deleted at 2012-09-17 10:35:36

------ reference ------------------------------------ ---


tried, it seems useless, turn out of the picture is still a mess
------ reference --------------------- ------------------
buddy, you solved now, I have encountered this problem, trouble posting a code, how to transform , or add and I am Q: 365938736 Come on a
------ reference ------------------------------------- -

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();
}

没有评论:

发表评论