See http://article.gmane.org/gmane.comp.java.lib.itext.general/21023/.

Paulo

----- Original Message ----- 
From: "Jonas" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Monday, January 01, 2007 2:57 PM
Subject: [iText-questions] Colors with alpha


> Hi,
>
> I recently experimented a little with transparent colors and I ran into a
> very strange
> behaviour: as soon as I use a color with alpha on a page, all other colors
> appear
> not in the intended way anymore. I created a demo class to show the effect
> (see below).
> On page one, where I don't have any transparent color, all colors look
> correct. On
> page two, the magenta and the cyan suddenly look very grayish, which seems
> to be caused by the color with alpha.
> Is that a bug in itext or am I just doing something wrong?
>
> Thanks in advance for any hints on how to deal with this...
>
> Cheers,
> Jonas
>
> --------------------------------------------- snip
> -----------------------------------------------------------
> public class ColorsWithAlphaTest {
>
>  /**
>   * @param args
>   */
>  public static void main(String[] args) {
>    try {
>      Document document = new Document(PageSize.A4.rotate());
>      OutputStream out = new FileOutputStream("c:/tmp/test.pdf");
>      PdfWriter writer = PdfWriter.getInstance(document, out);
>
>      document.open();
>
>      document
>          .add(new Phrase("Page without transparency: colors look
> correct"));
>
>      document.add(getSquare(writer, Color.magenta));
>      document.add(getSquare(writer, Color.cyan));
>      document.add(getSquare(writer, new Color(75, 75, 75))); // color
> without
>                                                              // alpha!
>
>      document.newPage();
>
>      document.add(new Phrase(
>          "Page with alpha somewhere: colors look bad"));
>
>      document.add(getSquare(writer, Color.magenta));
>      document.add(getSquare(writer, Color.cyan));
>      document.add(getSquare(writer, new Color(75, 75, 75, 75))); // color
> with
>                                                                  // alpha!
>
>      document.close();
>      out.close();
>
>    } catch (Exception e) {
>      e.printStackTrace();
>    }
>  }
>
>  private static Image getSquare(PdfWriter writer, Color c)
>      throws BadElementException {
>    int width = 15;
>    int height = 15;
>    final PdfContentByte cb = writer.getDirectContent();
>    cb.saveState();
>
>    PdfTemplate tp = cb.createTemplate(width, height);
>    Graphics2D g2 = tp.createGraphics(width, height);
>
>    g2.setColor(c);
>    g2.fillRect(0, 0, width, height);
>
>    g2.dispose();
>    cb.restoreState();
>
>    return Image.getInstance(tp);
>  }
>
> }
>


--------------------------------------------------------------------------------


> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share 
> your
> opinions on IT & business topics through brief surveys - and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV


--------------------------------------------------------------------------------


> _______________________________________________
> iText-questions mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/itext-questions
> Buy the iText book: http://itext.ugent.be/itext-in-action/
> 


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/

Reply via email to