Struct plotters_bitmap::BitMapBackend
source · pub struct BitMapBackend<'a, P: PixelFormat = RGBPixel> { /* private fields */ }
Expand description
The backend that drawing a bitmap
§Warning
You should call .present()?
on a
BitMapBackend
, not just drop
it or allow it to go out of scope.
If the BitMapBackend
is just dropped, it will make a best effort attempt to write the
generated charts to the output file, but any errors that occur (such as inability to
create the output file) will be silently ignored.
Implementations§
source§impl<'a> BitMapBackend<'a, RGBPixel>
impl<'a> BitMapBackend<'a, RGBPixel>
sourcepub fn new<T: AsRef<Path> + ?Sized>(path: &'a T, (w, h): (u32, u32)) -> Self
pub fn new<T: AsRef<Path> + ?Sized>(path: &'a T, (w, h): (u32, u32)) -> Self
Create a new bitmap backend
sourcepub fn gif<T: AsRef<Path>>(
path: T,
(w, h): (u32, u32),
frame_delay: u32,
) -> Result<Self, BitMapBackendError>
pub fn gif<T: AsRef<Path>>( path: T, (w, h): (u32, u32), frame_delay: u32, ) -> Result<Self, BitMapBackendError>
Create a new bitmap backend that generate GIF animation
When this is used, the bitmap backend acts similar to a real-time rendering backend.
When the program finished drawing one frame, use present
function to flush the frame
into the GIF file.
path
: The path to the GIF file to createdimension
: The size of the GIF imagespeed
: The amount of time for each frame to display
sourcepub fn with_buffer(buf: &'a mut [u8], (w, h): (u32, u32)) -> Self
pub fn with_buffer(buf: &'a mut [u8], (w, h): (u32, u32)) -> Self
Create a new bitmap backend which only lives in-memory
When this is used, the bitmap backend will write to a user provided u8 array (or Vec<u8>
)
in RGB pixel format.
Note: This function provides backward compatibility for those code that assumes Plotters
uses RGB pixel format and manipulates the in-memory framebuffer.
For more pixel format option, use with_buffer_and_format
instead.
buf
: The buffer to operatedimension
: The size of the image in pixels- returns: The newly created bitmap backend
source§impl<'a, P: PixelFormat> BitMapBackend<'a, P>
impl<'a, P: PixelFormat> BitMapBackend<'a, P>
sourcepub fn with_buffer_and_format(
buf: &'a mut [u8],
(w, h): (u32, u32),
) -> Result<Self, BitMapBackendError>
pub fn with_buffer_and_format( buf: &'a mut [u8], (w, h): (u32, u32), ) -> Result<Self, BitMapBackendError>
Create a new bitmap backend with a in-memory buffer with specific pixel format.
Note: This can be used as a way to manipulate framebuffer, mmap
can be used on the top of this
as well.
buf
: The buffer to operatedimension
: The size of the image in pixels- returns: The newly created bitmap backend
sourcepub fn split(&mut self, area_size: &[u32]) -> Vec<BitMapBackend<'_, P>>
pub fn split(&mut self, area_size: &[u32]) -> Vec<BitMapBackend<'_, P>>
Split a bitmap backend vertically into several sub drawing area which allows multi-threading rendering.
area_size
: The size of the area- returns: The split backends that can be rendered in parallel
Trait Implementations§
source§impl<'a, P: PixelFormat> DrawingBackend for BitMapBackend<'a, P>
impl<'a, P: PixelFormat> DrawingBackend for BitMapBackend<'a, P>
source§type ErrorType = BitMapBackendError
type ErrorType = BitMapBackendError
source§fn ensure_prepared(
&mut self,
) -> Result<(), DrawingErrorKind<BitMapBackendError>>
fn ensure_prepared( &mut self, ) -> Result<(), DrawingErrorKind<BitMapBackendError>>
source§fn present(&mut self) -> Result<(), DrawingErrorKind<BitMapBackendError>>
fn present(&mut self) -> Result<(), DrawingErrorKind<BitMapBackendError>>
ensure_prepared
is called
it checks if it needs a fresh buffer and present
is called rendering all the
pending changes on the screen.