You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "John Hewson (JIRA)" <ji...@apache.org> on 2015/09/01 08:03:45 UTC

[jira] [Commented] (PDFBOX-2949) Rendering to ARGB brings black background

    [ https://issues.apache.org/jira/browse/PDFBOX-2949?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14724845#comment-14724845 ] 

John Hewson commented on PDFBOX-2949:
-------------------------------------

It turns out that creating a new ARGB BufferedImage and saving it without doing any drawing results in a black image. I'd assumed that ARGB images were initialised to be transparent, not black. The solution is to set the background color to 0,0,0,0 immediately after the image has been created.

> Rendering to ARGB brings black background
> -----------------------------------------
>
>                 Key: PDFBOX-2949
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-2949
>             Project: PDFBox
>          Issue Type: Bug
>    Affects Versions: 2.0.0
>            Reporter: Tilman Hausherr
>         Attachments: dora.pdf, doraargb.png, dorargb.png
>
>
> As reported by [~jon_wu] in the user mailing list... instead of the somewhat long thread, here's code I tried:
> {code}
> try (PDDocument document = PDDocument.load(new File(dir, "dora.pdf")))
>         {
>             PDFRenderer pdfRenderer = new PDFRenderer(document);
>             BufferedImage bim = pdfRenderer.renderImageWithDPI(0, 300, ImageType.RGB);
>             ImageIO.write(bim, "png", new File(dir, "dorargb.png"));
>             bim = pdfRenderer.renderImageWithDPI(0, 300, ImageType.ARGB);
>             ImageIO.write(bim, "png", new File(dir, "doraargb.png"));
>         }
> {code}
> PDFRenderer has this:
> {code}
>         Graphics2D g = image.createGraphics();
>         if (imageType != ImageType.ARGB)
>         {
>             g.setBackground(Color.WHITE);
>         }
> {code}
> We could just remove the line with the "if" and the braces. The question is, is the current behaviour a fault or a feature? Note that the ARGB image has a detail that is invisible in the RGB image.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org