Creating a layer (PGraphic/PImage)
in
Programming Questions
•
1 year ago
Hi,
I am trying to create transparent layers,
I can do it by drawing each graphic individually but this takes too long.
To over come this problem I am trying to add all the graphics to PImages as soon as they are created.
This has led me to start using PGraphics to draw the graphics onto and then copy those graphics into a PImage.
The problem I am having is that I cannot get a transparent background on the PGraphics object from which I am copying the graphics.
Below is some code that should highlight the issue:
- PGraphics pg;
- PGraphics frame;
- PApplet papp=this;
- public void setup(){
- size(800,800);
- pg = createGraphics(papp.width, papp.height, JAVA2D);
- pg.background(255);
- }
- public void draw(){
- pg.beginDraw();
- pg.endDraw();
- }
- public void mousePressed(){
- rect(0,0,200,200);
- pg.beginDraw();
- pg.stroke(34);
- pg.fill(57);
- pg.rect(mouseX,mouseY,50,50);
- pg.line(25,25,67,89);
- pg.endDraw();
- PImage img=new PImage(papp.width,papp.height);
- img=pg.get(0,0,300,300);
- papp.image(img,20,20,0300,300);
- }
As you can see from running the above, it is setting a blue background for some unknown (to me) reason
1