nr_blit: Copy a native raster image into another at an arbitrary...

View source: R/nr-blit.R

nr_blitR Documentation

Copy a native raster image into another at an arbitrary location, scale and rotation

Description

Copy a whole image, or subset of an image, into the destination image and configure the angle and size of the copied image.

Usage

nr_blit(
  dst,
  src,
  x,
  y,
  xsrc = 0L,
  ysrc = 0L,
  w = -1L,
  h = -1L,
  hjust = 0.5,
  vjust = 0.5,
  angle = 0,
  scale = 1,
  use_alpha = TRUE
)

Arguments

dst, src

source and destination native raster images

x, y

Location in dst to place the src image. These values must be vectors of the same length. If the length is greater than 1, then the src will be pasted into dst at multiple locations.

xsrc, ysrc

Upper-left coordinates of the bounding box within the src image to copy. Default: (0, 0)

w, h

Width and height of the bounding box within the src to copy. If size is negative, then the actual width/height of the src is used. Default: (-1, -1)

hjust, vjust

specify horizontal and vertical justification of the handle on the src image to be placed at (x, y) within the dst image. Default (0, 0) is to use the top-left corner of the image as the handle. Use (0.5, 0.5) to centre the src image at the dst location (x, y)

angle

Rotation angle (clockwise) in radians. Default: 0. If this is a vector, then the src will be pasted into the dst at multiple angles.

scale

Zoom factor. Default: 1. IF this is a vector, then the src will be pasted into dst at multiple scales.

use_alpha

Use alpha channel when drawing? Logical. Default: TRUE

Details

This operation is vectorised such that a single src image can be pasted multiple times into the dst image with varying location, angle and scale.

Value

Invisibly return the supplied dst native raster image which was been modified in-place

See Also

Other blitting functions: nr_blit_multi()

Examples

nr <- nr_new(50, 50, 'grey80')
nr_blit(dst = nr, src = deer[[1]], x = 25, y = 25)
plot(nr)

nr <- nr_new(300, 200, 'grey80')
sq <- nr_new(20, 20, 'darkblue')
nr_blit(nr, src = sq, x = 100, y = 100, angle = pi/3, scale = 5)
plot(nr)

nr <- nr_new(800, 600, 'grey80')
sq <- fastpng::read_png(system.file("image/deer-1.png", package="nara"), type = 'nativeraster')
nr_blit(nr, src = sq, x = 300, y = 240, angle = pi/2, scale = 1)
plot(nr)

nara documentation built on May 28, 2026, 5:07 p.m.