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 & HelpSyntax Questions › saveFrame with transparency
Page Index Toggle Pages: 1
saveFrame with transparency? (Read 282 times)
saveFrame with transparency?
Mar 24th, 2009, 1:06pm
 
hi all,

i am trying to create a movie file with an embedded alpha channel - is this possible?

i have started by trying to take the approach of exporting a graphic each frame as a .png image and then reassembling these in quicktime; problem is:

1. I can't seem to get the pg.saveFrame() option working for exporting the graphic; it will only do pg.save() which overwrites the file every frame; not much use

2. the image produced doesn't have the background, which is great but the rest of the graphic's pixels don't have any transparency/alpha channel quality to them; they are solid; i want them to have the transparency they are drawn with

any pointers anyone?

thanks
S

Quote:
import processing.pdf.*;
PGraphics pg;

ArrayList drops;
float X = random(0,width);
float Y = random(0,height);
int raining;
int a = 5000;
PFont font;
boolean faster=true;

void setup(){
  size(1680,1050);
  drops = new ArrayList();
  pg = createGraphics(width, height, JAVA2D);
  font = loadFont("Surface-Medium-13.vlw");
  textFont( font );
}


void draw(){
  pg.beginDraw();
  pg.smooth();
  background(0);    
  //beginRecord(PDF, "droplets-####.pdf");  
  //fill(0,200);
  //text("mouse over a droplet to delete it",10,10);
  for (int j = drops.size()-1; j >= 0; j--) {
       Drop drop = (Drop) drops.get(j);
       drop.drawdrop();
       if (drop.finished()){
          drops.remove(j);
  }}
  if (millis() - raining > (random(0,a))){
    rain();
    raining = millis();
    if (a<=-12000){
      faster = false;}
    if(a>=5000){
      faster = true;}
    if (faster){
      a = a-100;}
    else{  a=a+100;}
  }
  pg.endDraw();
  image(pg, 0, 0);
  pg.save("droplets-####.png");
  //endRecord();
}


void rain(){
  X = random(0,width);
  Y = random(0,height);
  drops.add(new Drop(X,Y));
}





Quote:
class Drop{
  int xpos;
  int ypos;
  float i;
  int o;
  int col = int(random(0,100));
  int xDim = int(random(0,30));
  int yDim = int(random(0,30));
  float dropswell = random(1,2);
  boolean rising=true;
  
  Drop(float x,float y) {
    xpos = int (x);
    ypos = int (y);
  }
  
void drawdrop(){
  if (col>=15){
    pg.fill(0,0,255,255-o);}
  else{
    pg.fill(255,0,0,255-o);}
  pg.noStroke();
  pg.ellipse(xpos,ypos,xDim+i,xDim+i);
  if((255-o)<80){
    rising = false;}
  if(rising){
    i++; o++;}
  if(!rising){
    i=i-0.5; o++;}  
}  

boolean finished(){
  if ((dist(mouseX,mouseY,xpos,ypos)<20)||((255-o)<0)){
    return true;}
  else{
    return false;}}
    
}



Re: saveFrame with transparency?
Reply #1 - Mar 24th, 2009, 1:36pm
 
sam_mcelhinney wrote on Mar 24th, 2009, 1:06pm:
i am trying to create a movie file with an embedded alpha channel - is this possible

I am not specialist of movie formats, but I never heard such thing is possible.
At best you can make an animated Gif (unlikely given the size you need!) or an MNG file (not a popular format, alas).

Quote:
1. I can't seem to get the pg.saveFrame() option working for exporting the graphic; it will only do pg.save() which overwrites the file every frame; not much use

Ah, indeed. saveFrame is specifically designed to save a displayed frame. Of course, you can use save() with a computed file name. Or just use the available (but not in Extended Reference) functions used by saveFrame:

pg.save(savePath(insertFrame("droplets-####.png")));

Quote:
2. the image produced doesn't have the background, which is great but the rest of the graphic's pixels don't have any transparency/alpha channel quality to them; they are solid; i want them to have the transparency they are drawn with

I don't have this problem, the fill colors have the requested transparency in the saved files.
Page Index Toggle Pages: 1