[−][src]Crate tinybmp
Small BMP format image parser supporting no-std environments. Specifically designed to work with embedded-graphics
Examples
Load a BMP image and check its Header
and returned pixels.
use tinybmp::{Bmp, FileType, Header, Pixel}; let bmp = Bmp::from_slice(include_bytes!("../tests/chessboard-8px-24bit.bmp")) .expect("Failed to parse BMP image"); // Read the BMP header assert_eq!( bmp.header, Header { file_type: FileType::BM, file_size: 314, reserved_1: 0, reserved_2: 0, image_data_start: 122, bpp: 24, image_width: 8, image_height: 8, image_data_len: 192 } ); // Check that raw image data slice is the correct length (according to parsed header) assert_eq!(bmp.image_data().len(), bmp.header.image_data_len as usize); // Get an iterator over the pixel coordinates and values in this image and load into a vec let pixels: Vec<Pixel> = bmp.into_iter().collect(); // Loaded example image is 8x8px assert_eq!(pixels.len(), 8 * 8);
Integrate with embedded-graphics
This example loads a 16BPP image and draws it to an embedded-graphics compatible display.
The graphics
feature must be enabled for embedded-graphics support.
use embedded_graphics::{image::Image, prelude::*}; use tinybmp::Bmp; // Load 16BPP 8x8px image let bmp = Bmp::from_slice(include_bytes!("../tests/chessboard-8px-color-16bit.bmp")).unwrap(); let image = Image::new(&bmp, Point::zero()); image.draw(&mut display)?;
Structs
Bmp | A BMP-format bitmap |
BmpIterator | Iterator over individual BMP pixels |
Header | BMP header information |
Pixel | A single pixel of a BMP image |
Enums
FileType | Bitmap file type |