We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › transparency in gif and pngs
Page Index Toggle Pages: 1
transparency in gif and pngs (Read 604 times)
transparency in gif and pngs
Jan 14th, 2008, 11:20pm
 
I've been trying to load up a transparent gif/png as a PImage, and copied into another PImage. But the transparency is not retained. Is that supposed to happen?
Re: transparency in gif and pngs
Reply #1 - Jan 15th, 2008, 9:47am
 
they should be retained.

post the image somewhere online?
Re: transparency in gif and pngs
Reply #2 - Jan 16th, 2008, 8:56am
 
PImage a,b;

void setup(){
size(1200,800);
a=loadImage("pic.png"); // and the gif version as well
background(255);
b=new PImage(400,500);
b.copy(a,50,50,400,500,0,0,400,500);

}

void draw(){
   background(255);
  image(a,0,0);
  //image(a,random(800),random(500));
   image(a,400,50);
  image(b,400,400);

}

the copied image doesn't retain alpha at all for either the png or the gif version.

!!!
Re: transparency in gif and pngs
Reply #3 - Jan 16th, 2008, 2:50pm
 
it's because the PImage "b" is created with RGB color, while you want it to be ARGB (including alpha).

So, replace your line

   b=new PImage(400,500);

with

   b=new PImage(400,500,ARGB);

et voilà!
Re: transparency in gif and pngs
Reply #4 - Jan 16th, 2008, 5:51pm
 
Hey that's great!

The reference documentation never showed that particular constructor signature.
Re: transparency in gif and pngs
Reply #5 - Jan 16th, 2008, 5:55pm
 
Oh is there anyway to toggle the transparency of a PImage?
Page Index Toggle Pages: 1