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 & HelpOther Libraries › PDF recorder ignores transpency with image(...)
Page Index Toggle Pages: 1
PDF recorder ignores transpency with image(...) (Read 796 times)
PDF recorder ignores transpency with image(...)
Sep 10th, 2009, 10:31am
 
Hey. While I was updating the NextText library, I came across a problem with the PDF recorder. As a work around to Procressing's limitations for rendering complex shapes (with holes), the NextText P2D renderer draws to a buffer PImage and then slaps that on the PApplet by calling image(...).

To make sure that this image does not cover previous drawn objects, its background is set to fully transparent. This works smoothly on screen. The simple code below shows a green background with a transparent white circle in the middle.

The problem comes with the exported PDF which seems to drop any kind of transparency. The exported PDF shows a white background with an opaque white circle.

Bug or something i'm missing?

Code:
import processing.pdf.*;

PGraphics pg;

void setup() {
size(600, 400, P2D);
pg = createGraphics(width, height, JAVA2D);
pg.beginDraw();
pg.background(0x00ffffff);
pg.smooth();
pg.stroke(0);
pg.fill(255, 100);
pg.ellipse(width/2, height/2, 25, 25);
pg.endDraw();
noLoop();
}

void draw() {
beginRecord(PDF, "outitgoes.pdf");
background(30, 180, 40);
image(pg, 0, 0);
endRecord();
}
Re: PDF recorder ignores transpency with image(...)
Reply #1 - Sep 10th, 2009, 12:23pm
 
A PImage is naturally transparent. IIRC, your call to background() is ruining this, even if you draw with full transparency. At least it is not really necessary, you should try without it.

[EDIT] Mmm, it doesn't work. Now that I think of it, one issue is that you draw a bitmap image in the PDF, which looks uglier than drawing directly on the surface: try to zoom in your circle to see what I mean.

PS.: It looks like the PDF library doesn't support drawing images with transparency: I loaded a PNG image and drew it, and it has also a black background.
Re: PDF recorder ignores transpency with image(...)
Reply #2 - Sep 12th, 2009, 10:19am
 
Thanks. That's good to know.

It is worth flagging as a bug? I know that PDF / PostScript handle transparency a bit funny, but it should be able to handle this.
Page Index Toggle Pages: 1