Sunday, October 06, 2013

Processing.js Save Part of Sketch Window

I'm working on a save feature for a web app for drawing musical compositions. I want to make sure you can save your drawn composition and reload them instead of having to recreate them. Processing.js  has a save() method but I was thinking it was a dead end because it saves either the whole sketch window or a loaded image in the sketch, of which the drawn composition is neither. But this tip from the forum saved the day. Use get() to capture the region where the composition is drawn and define that as an image, then call save on that!
void trySaveImage() {
  if(mouseX > width-40 && mouseY < 40) {
    PImage drawWindow = get(20, top, width-20, height-top);"drawing.png");

Now I just have to figure out how to load the saved image...

No comments :