Faster way to draw part of an image?

i need to be able to draw the top part of an image, here’s what i have

void drawImageSplice(PGraphics pg,PImage img,int x,int y,int w,int h,float cut){
  int yp = round(h*cut);
    PGraphics buffer = createGraphics(w,yp);

this works great locally but in a live html canvas it’s very slow. is there a faster way to do this? thanks

The clip function may be of use, since it allows you to temporarily draw only in specific rectangle on screen


oh that’s perfect thanks

wait apparently this doesn’t work in html at all. like it just stops the program immediately

it works great in local processing but in live html with a processing canvas it goes blank immediately. even just calling noClip() breaks the canvas.


Then an alternative which avoids making new PGraphics is the copy() method, which allows you to copy a certain rectangle of an image using the underlying pixels array. This may be more memory efficient, since you are not creating a new PGraphics every time you draw the image, but it likely isn’t much faster since you are copying pixels rather than drawing an image using image(). I haven’t tested the speed of this function, but it may be worth a shot.


do you know if clip() can be used in html. i still can’t get it to run for some reason