Skip to content
draw_image

draw_image

Mojo function 🡭

draw_image

fn def draw_image(mut dst: Canvas, image: Canvas, x: Float64, y: Float64, width: Float64 = 0, height: Float64 = 0)

Draw image as a block of cells with its top-left at (x, y), scaled to width x height (its own pixel size when 0), in the coordinates the shapes use and under the canvas transform: DrawTarget.draw_image on the raster backend, and the call for a heatmap, an image plot, or a rendered panel placed in a figure.

Each image pixel is one cell of the block. A canvas pixel takes the cell its center falls in, so cells stay hard-edged at any scale and no color the image did not hold appears; a translucent cell blends source-over, as a shape would, and a clip applies. The matrix overloads of draw_canvas place a source by its pixel corners and this places one by the shapes’ rule, pixel k spanning k - 0.5 to k + 0.5: under a scale and translation, including the supersampling recipe on downsample, every cell edge snaps as fill_rect snaps a rectangle’s edge at the same coordinate, so the block covers the pixels a fill_rect per cell would. Under a rotation or shear the block is sampled through the matrix path with Filter.NEAREST, on the same convention.

Args:

  • dst (Canvas): Canvas drawn onto.
  • image (Canvas): The cells to draw. Unchanged.
  • x (Float64): Left edge, in user coordinates.
  • y (Float64): Top edge.
  • width (Float64): Drawn width, or 0 for image.width.
  • height (Float64): Drawn height, or 0 for image.height.

Raises:

Error: The canvas transform is singular.