카메라가 실제로 BMP 형식을 전송하면 데이터를 디스크에 쓸 수 있습니다. 그러나 더 많은 가능성이 있습니다 (그리고 이것은 링크에서 사양을 읽는 것 같습니다), 카드는 원시 비트 맵을 보냅니다. 이는 동일하지 않습니다. 카드 사양 PDF에서이 정보를 사용하여
:
원시 이미지를 통해 덤프를 직렬 또는 플래시 카드에
- (640 : 320 : 160 : 80) × (480 : 240 : 120 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