カメラが真にBMP形式を送信する場合は、データをディスクに書き込むだけで済みます。しかし、より多くの可能性があります(そして、あなたのリンクから仕様を読んでいるようです)、カードは同じではない生のビットマップを送信します。カード仕様PDFからこの情報を使用
:
RAW画像は、シリアルまたはフラッシュカードに
- 上ダンプ
(640:320:160:80)X(480:120:240 :60)画像解像度
- RGB565/YUV655色空間
RGB565画素レイアウトmentione上記のdはBufferedImage.TYPE_USHORT_565_RGB
と完全に一致するはずですので、使用するのが最も簡単です。
byte[] bytes = ... // read from serial port
ShortBuffer buffer = ByteBuffer.wrap(bytes)
.order(ByteOrder.BIG_ENDIAN) // Or LITTLE_ENDIAN depending on the spec of the card
.asShortBuffer(); // Our data will be 16 bit unsigned shorts
// Create an image matching the pixel layout from the card
BufferedImage img = new BufferedImage(640, 480, BufferedImage.TYPE_USHORT_565_RGB);
// Get the pixel data from the image, and copy the data from the card into it
// (the cast here is safe, as we know this will be the case for TYPE_USHORT_565_RGB)
short[] data = ((DataBufferUShort) img.getRaster().getDataBuffer()).getData();
buffer.get(data);
// Finally, write it out as a proper BMP file
ImageIO.write(img, "BMP", new File("temp.bmp"));
PS:上記のコードは(私は明らかに、このようなカードを持っていないとして)ランダムなデータで初期化長さ640 * 480 * 2のbyte
配列を使用して、私のために動作します。
ありがとうございます。 – NYoussef