Struct embedded_graphics_simulator::OutputImage
source · pub struct OutputImage<C> { /* private fields */ }Expand description
Output image.
An output image is the result of applying OutputSettings to a SimulatorDisplay. It can
be used to save a simulator display to a PNG file.
Implementations§
source§impl<C> OutputImage<C>where
C: PixelColor + From<Rgb888> + ToBytes,
<C as ToBytes>::Bytes: AsRef<[u8]>,
impl<C> OutputImage<C>where C: PixelColor + From<Rgb888> + ToBytes, <C as ToBytes>::Bytes: AsRef<[u8]>,
sourcepub fn update<DisplayC>(&mut self, display: &SimulatorDisplay<DisplayC>)where
DisplayC: PixelColor + Into<Rgb888>,
pub fn update<DisplayC>(&mut self, display: &SimulatorDisplay<DisplayC>)where DisplayC: PixelColor + Into<Rgb888>,
Updates the image from a SimulatorDisplay.
source§impl<C: OutputImageColor> OutputImage<C>
impl<C: OutputImageColor> OutputImage<C>
sourcepub fn save_png<PATH: AsRef<Path>>(&self, path: PATH) -> ImageResult<()>
pub fn save_png<PATH: AsRef<Path>>(&self, path: PATH) -> ImageResult<()>
Saves the image content to a PNG file.
Examples found in repository?
examples/png-file.rs (line 33)
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
fn main() {
let mut display = SimulatorDisplay::<BinaryColor>::new(Size::new(256, 64));
let large_text = MonoTextStyle::new(&FONT_10X20, BinaryColor::On);
let centered = TextStyleBuilder::new()
.baseline(Baseline::Middle)
.alignment(Alignment::Center)
.build();
Text::with_text_style(
"embedded-graphics",
display.bounding_box().center(),
large_text,
centered,
)
.draw(&mut display)
.unwrap();
let output_settings = OutputSettingsBuilder::new().scale(2).build();
let output_image = display.to_rgb_output_image(&output_settings);
let path = std::env::args_os()
.nth(1)
.expect("expected PNG file name argument");
output_image.save_png(path).unwrap();
}sourcepub fn to_base64_png(&self) -> ImageResult<String>
pub fn to_base64_png(&self) -> ImageResult<String>
Returns the image as a base64 encoded PNG.
Examples found in repository?
examples/png-base64.rs (line 32)
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
fn main() {
let mut display = SimulatorDisplay::<BinaryColor>::new(Size::new(256, 64));
let large_text = MonoTextStyle::new(&FONT_10X20, BinaryColor::On);
let centered = TextStyleBuilder::new()
.baseline(Baseline::Middle)
.alignment(Alignment::Center)
.build();
Text::with_text_style(
"embedded-graphics",
display.bounding_box().center(),
large_text,
centered,
)
.draw(&mut display)
.unwrap();
let output_settings = OutputSettingsBuilder::new().scale(2).build();
let output_image = display.to_grayscale_output_image(&output_settings);
println!(
"<img src=\"data:image/png;base64,{}\">",
output_image.to_base64_png().unwrap()
);
}sourcepub fn as_image_buffer(&self) -> ImageBuffer<C::ImageColor, &[u8]>
pub fn as_image_buffer(&self) -> ImageBuffer<C::ImageColor, &[u8]>
Returns the output image as an image crate ImageBuffer.
Trait Implementations§
source§impl<C: Clone> Clone for OutputImage<C>
impl<C: Clone> Clone for OutputImage<C>
source§fn clone(&self) -> OutputImage<C>
fn clone(&self) -> OutputImage<C>
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moresource§impl<C: Debug> Debug for OutputImage<C>
impl<C: Debug> Debug for OutputImage<C>
source§impl<C> OriginDimensions for OutputImage<C>
impl<C> OriginDimensions for OutputImage<C>
source§impl<C: PartialEq> PartialEq<OutputImage<C>> for OutputImage<C>
impl<C: PartialEq> PartialEq<OutputImage<C>> for OutputImage<C>
source§fn eq(&self, other: &OutputImage<C>) -> bool
fn eq(&self, other: &OutputImage<C>) -> bool
This method tests for
self and other values to be equal, and is used
by ==.impl<C: Eq> Eq for OutputImage<C>
impl<C> StructuralEq for OutputImage<C>
impl<C> StructuralPartialEq for OutputImage<C>
Auto Trait Implementations§
impl<C> RefUnwindSafe for OutputImage<C>where C: RefUnwindSafe,
impl<C> Send for OutputImage<C>where C: Send,
impl<C> Sync for OutputImage<C>where C: Sync,
impl<C> Unpin for OutputImage<C>where C: Unpin,
impl<C> UnwindSafe for OutputImage<C>where C: UnwindSafe,
Blanket Implementations§
source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where T: CheckedCast<Dst>,
Casts the value.
source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere Src: CheckedCast<Dst>,
source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Casts the value.
§impl<T> Dimensions for Twhere
T: OriginDimensions,
impl<T> Dimensions for Twhere T: OriginDimensions,
§fn bounding_box(&self) -> Rectangle
fn bounding_box(&self) -> Rectangle
Returns the bounding box.
source§impl<T> OverflowingAs for T
impl<T> OverflowingAs for T
source§fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool)where T: OverflowingCast<Dst>,
Casts the value.
source§impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere Src: OverflowingCast<Dst>,
source§fn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
Casts the value.
§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<T> SaturatingAs for T
impl<T> SaturatingAs for T
source§fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dstwhere T: SaturatingCast<Dst>,
Casts the value.
source§impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere Src: SaturatingCast<Dst>,
source§fn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
Casts the value.
source§impl<T> UnwrappedAs for T
impl<T> UnwrappedAs for T
source§fn unwrapped_as<Dst>(self) -> Dstwhere
T: UnwrappedCast<Dst>,
fn unwrapped_as<Dst>(self) -> Dstwhere T: UnwrappedCast<Dst>,
Casts the value.
source§impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere
Src: UnwrappedCast<Dst>,
impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere Src: UnwrappedCast<Dst>,
source§fn unwrapped_cast_from(src: Src) -> Dst
fn unwrapped_cast_from(src: Src) -> Dst
Casts the value.
source§impl<T> WrappingAs for T
impl<T> WrappingAs for T
source§fn wrapping_as<Dst>(self) -> Dstwhere
T: WrappingCast<Dst>,
fn wrapping_as<Dst>(self) -> Dstwhere T: WrappingCast<Dst>,
Casts the value.
source§impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere
Src: WrappingCast<Dst>,
impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere Src: WrappingCast<Dst>,
source§fn wrapping_cast_from(src: Src) -> Dst
fn wrapping_cast_from(src: Src) -> Dst
Casts the value.