I have geomerative installed to modify an svg. I want to save an image with a transparent background whenever I left-click. However, using the code below, whenever I left click it only saves an image of the unmodified svg with a transparent background.
import geomerative.*;
RShape grp;
PGraphics img;
int first = 0;
void setup(){
size(600, 600);
RG.init(this);
background(#2D4D83);
img = createGraphics(width, height);
grp = RG.loadShape("bot1.svg");
grp = RG.centerIn(grp, g);
}
void draw(){
img.beginDraw();
img.translate(width/2, height/2);
translate(width/2, height/2);
float t = map(mouseX, 0, width, 0, 1);
RShape[] splittedGroups = grp.splitPaths(t);
RG.shape(splittedGroups[first]);
grp.draw(img);
img.endDraw();
}
void mousePressed(){
first = (first + 1) % 2;
img.save("image_" + millis() + ".png");
}
Not sure how I can make the draw
command recognise the modified svg image.
Impossible to transform a RShape in PShape, so I found this alternative :
import geomerative.*;
RShape grp;
PGraphics img;
int first = 0;
PImage buf;
void setup() {
size(600, 600);
RG.init(this);
background(#2D4D83);
img = createGraphics(width, height);
buf = createImage(width, height, RGB);
grp = RG.loadShape("tiger.svg");
grp = RG.centerIn(grp, g);
}
void draw() {
img.beginDraw();
img.translate(width/2, height/2);
translate(width/2, height/2);
float t = map(mouseX, 0, width, 0, 1);
RShape[] splittedGroups = grp.splitPaths(t);
RG.shape(splittedGroups[first]);
grp.draw(img);
img.endDraw();
loadPixels();
for (int i = 0; i < img.pixels.length; i++) {
buf.pixels[i] = pixels[i];
}
updatePixels();
}
void mousePressed() {
first = (first + 1) % 2;
buf.save("image_" + millis() + ".png");
}
Thanks! This helps with save an image but not with saving a transparent image. Any thoughts on how to save a transparent image?
debxyz
October 7, 2022, 5:14pm
4
matheplica:
background(#2D4D83);
You might try commenting out the background line to see if that makes a difference.
Not sure if this is THE solution, but it is where I would start.
Doesn’t work sadly. It just saves an image with the default light grey background (and with animation frames overlaid as the background isn’t redrawn)
debxyz
October 7, 2022, 11:51pm
6
This is an interesting thread which may be of help:
So I made this code where you can draw and create an image. This works just fine but is it possible to get an image with a transparant background? Is there like a function to remove everything with RGB code white in a certain area?
Code:
float oldX;
float oldY;
PImage test;
void setup(){
fullScreen();
background(255);
rect(40, 150, 200 ,100);
test = loadImage("test.jpg");
}
void draw(){
if(mousePressed){
line(mouseX, mouseY, oldX, oldY);
}
oldX = mouseX;
oldY = mouseY;
if(key…
Thanks but it doesn’t help either. As @matheplica pointed out it’s not possible to convert an RShape into a PShape (which the method you posted uses).