pub struct Canvas {
pub pixmap: Pixmap,
pub scale: f32,
/* private fields */
}Expand description
A Canvas is an abstraction over a tiny-skia Pixmap that allows for drawing at different
scales. This allows for using the same drawing commands to produce images of different sizes.
§Example
use wassily_core::*;
use tiny_skia::Color;
fn draw(canvas: &mut Canvas) {
canvas.fill(Color::from_rgba8(128, 128, 128, 255));
let center = pt(canvas.width() / 2, canvas.height() / 2);
Shape::new()
.ellipse(center, 300.0, 200.0)
.fill_color(Color::from_rgba8(75, 0, 130, 255))
.stroke_color(Color::from_rgba8(255, 165, 0, 255))
.stroke_weight(10.0)
.draw(canvas);
}
fn main() {
let mut canvas1 = Canvas::new(500, 500);
// Draw a 300x200 ellipse at the center of a 500 x 500 canvas.
draw(&mut canvas1);
let mut canvas2 = Canvas::with_scale(500, 500, 2.0);
// Draw a 600x400 ellipse at the center of a 1000 x 1000 canvas. That is,
// the exact same image as above, but, double the width and height.
draw(&mut canvas2);
canvas1.save_png("./scale1.png");
canvas2.save_png("./scale2.png");
}Fields§
§pixmap: PixmapThe underlying tiny-skia Pixmap.
scale: f32The scale factor of the canvas. This is the factor by which the width and height are scaled. For example, a scale of 2.0 means that the width and height are doubled when rendering.
Implementations§
Source§impl Canvas
impl Canvas
pub fn from_image(image: &DynamicImage) -> Canvas
Sourcepub fn with_scale(width: u32, height: u32, scale: f32) -> Canvas
pub fn with_scale(width: u32, height: u32, scale: f32) -> Canvas
Create a new Canvas with a scale factor. The actual size of the canvas is the width times
the scale and the height times the scale. However, all drawing commands should use the
pre-scaled width and height.
pub fn width(&self) -> u32
Sourcepub fn fill_path(
&mut self,
path: &Path,
paint: &mut Paint<'_>,
fill_rule: FillRule,
transform: Transform,
clip_mask: Option<&Mask>,
)
pub fn fill_path( &mut self, path: &Path, paint: &mut Paint<'_>, fill_rule: FillRule, transform: Transform, clip_mask: Option<&Mask>, )
Fill the path with a Paint.
Sourcepub fn fill_rect(
&mut self,
rect: Rect,
paint: &mut Paint<'_>,
transform: Transform,
clip_mask: Option<&Mask>,
)
pub fn fill_rect( &mut self, rect: Rect, paint: &mut Paint<'_>, transform: Transform, clip_mask: Option<&Mask>, )
Fill a rectangle with a Paint.
Sourcepub fn stroke_path(
&mut self,
path: &Path,
paint: &mut Paint<'_>,
stroke: &Stroke,
transform: Transform,
clip_mask: Option<&Mask>,
)
pub fn stroke_path( &mut self, path: &Path, paint: &mut Paint<'_>, stroke: &Stroke, transform: Transform, clip_mask: Option<&Mask>, )
Stroke a path with a Paint.
Sourcepub fn dot(&mut self, x: f32, y: f32, color: Color)
pub fn dot(&mut self, x: f32, y: f32, color: Color)
Color a single pixel on the canvas. !!! Warning this function will not scale with the canvas.
pub fn data(&self) -> &[u8] ⓘ
pub fn take(self) -> Vec<u8> ⓘ
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Canvas
impl RefUnwindSafe for Canvas
impl Send for Canvas
impl Sync for Canvas
impl Unpin for Canvas
impl UnwindSafe for Canvas
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more