I am wondering if it is possible to clip/save a specified area of the canvas to a local jpg/png file using P5.js. I'm aware of the save() function. However, as far as I know, it only saves the canvas as whole. Any ideas?
save()
Thanks!
You could do this:
get()
createGraphics()
set()
Here's a simple example:
let pg; function setup() { createCanvas(100, 100); pg = createGraphics(50, 50); } function draw() { background(200); pg.background(100); pg.noStroke(); pg.ellipse(pg.width / 2, pg.height / 2, 25, 25); image(pg, 25, 25); } function mousePressed(){ save(pg, "test.png"); }
More info can be found in the reference.
You could do this:
get()
function to get the pixel values of a certain regioncreateGraphics()
function to create a bufferset()
on that buffer object and pass in the pixel array you createdsave()
and pass that buffer object in as the first argumentHere's a simple example:
More info can be found in the reference.