A small 2D graphics library to draw things on embedded graphical LCDs, like the SSD1306 OLED display.
This crate aims to make drawing 2D graphics primitives super easy. It currently supports the following:
.bmp
) images at 1, 8 or 16BPP (requires bmp
feature).tga
) images (requires tga
feature)A core goal is to do the above without using any buffers; the crate should work without a
dynamic memory allocator and without pre-allocating large chunks of memory. To achieve this, it
takes an Iterator
based approach, where pixel values and positions are calculated on the fly,
with the minimum of saved state. This allows the consuming application to use far less RAM at
little to no performance penalty.
More information and up to date docs can be found on docs.rs.
Example usage can be found in the simulator:
```rust use embeddedgraphics::prelude::*; use embeddedgraphics::fonts::Font6x8; use embeddedgraphics::primitives::{Circle, Line}; use embeddedgraphics::pixelcolor::BinaryColor;
// Only used for examples - this would be replaced by the driver for your chosen display use embeddedgraphics::mockdisplay::MockDisplay as Display;
fn main() { // Create a display object to draw into // This will be whichever display driver you decide to use, like the SSD1306, SSD1351, etc let mut display = Display::new();
display.draw(Circle::new(Point::new(64, 64), 64).stroke(Some(BinaryColor::On)));
display.draw(Line::new(Point::new(64, 64), Point::new(0, 64)).stroke(Some(BinaryColor::On)));
display.draw(Line::new(Point::new(64, 64), Point::new(80, 80)).stroke(Some(BinaryColor::On)));
display.draw(
Font6x8::render_str("Hello World!")
.stroke(Some(BinaryColor::On))
.translate(Point::new(5, 50)),
);
} ```
Macros are also supported for text and primitives:
```rust use embeddedgraphics::prelude::*; use embeddedgraphics::pixelcolor::BinaryColor; use embeddedgraphics::{egcircle, egline, egrectangle, text6x8, egtriangle};
// Only used for examples - this would be replaced by the driver for your chosen display use embeddedgraphics::mockdisplay::MockDisplay as Display;
fn main() { // Create a display object to draw into // This will be whichever display driver you decide to use, like the SSD1306, SSD1351, etc let mut display = Display::new();
display.draw(egcircle!((64, 64), 64, stroke = Some(BinaryColor::On)));
display.draw(egline!((64, 64), (0, 64), stroke = Some(BinaryColor::On)));
display.draw(egline!((64, 64), (80, 80), stroke = Some(BinaryColor::On)));
display.draw(egrectangle!((64, 64), (80, 80), stroke = None, fill = Some(BinaryColor::Off)));
display.draw(text_6x8!("Hello world!", stroke = Some(BinaryColor::On)).translate(Point::new(5, 50)));
} ```
nalgebra_support
- use the Nalgebra crate with no_std
support to enable conversions from nalgebra::Vector2
to Coord
and UnsignedCoord
.bmp
- use the TinyBMP crate for BMP image support.tga
- use the TinyTGA crate for TGA image support.There may be other drivers out there we don't know about yet. If you know of a driver to add to this list, please open an issue!
All source font PNGs are taken from the excellent Uzebox Wiki page.
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.