You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Tilman Hausherr (JIRA)" <ji...@apache.org> on 2018/04/23 19:10:00 UTC

[jira] [Commented] (PDFBOX-4205) LosslessFactory alters image

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

Tilman Hausherr commented on PDFBOX-4205:
-----------------------------------------

I can reproduce the effect, but I don't know what is really going on. When viewed with IrfanView, it is said to have 40 different colors. When counted in java, it is said to have 28 different colors.

Tests by comparing the pixels in java pass.

There is a workaround, draw your TYPE_BYTE_GRAY image on an RGB image:

        BufferedImage image2 = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_RGB);
        Graphics g = image2.getGraphics();
        g.drawImage(image, 0, 0, null);
        g.dispose();
        image = image2;
 
But now a test that I created with your file no longer passes, an expected 255 255 255 color becomes 254 254 254.


> LosslessFactory alters image
> ----------------------------
>
>                 Key: PDFBOX-4205
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-4205
>             Project: PDFBox
>          Issue Type: Bug
>    Affects Versions: 2.0.7, 2.0.8, 2.0.9
>         Environment: Ubuntu 16.04
>            Reporter: Harry Dent
>            Priority: Minor
>         Attachments: lossy.png, picture_of_text.png
>
>
> The attached grayscale png becomes lighter when run through the following code snippet: 
> {code:java}
> BufferedImage image = ImageIO.read(new File("picture_of_text.png"));
> PDImageXObject xObject = LosslessFactory.createFromImage(new PDDocument(), image);
> BufferedImage lossy = xObject.getImage();
> ImageIO.write(lossy, "png", new File("lossy.png"));
> {code}
> The difference is easiest to spot by looking at the "S" in "41st". The loss in quality occurs in {{createFromImage()}} (rather than {{getImage()}}), which can be shown by embedding the {{PDImageXObject}} into a {{PDDocument}} and then saving this document to a file. 
>  
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

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