BufferedImage color saturation
Asked Answered
S

1

6

I'm writing a simple scanning application using jfreesane and Apache PDFBox.

Here is the scanning code:

InetAddress address = InetAddress.getByName("192.168.0.17");
SaneSession session = SaneSession.withRemoteSane(address);
List<SaneDevice> devices = session.listDevices();
SaneDevice device = devices.get(0);
device.open();
device.getOption("resolution").setIntegerValue(300);

BufferedImage bimg = device.acquireImage();
File file = new File("test_scan.png");
ImageIO.write(bimg, "png", file);

device.close();

And making PDF:

PDDocument document = new PDDocument();
float width = bimg.getWidth();
float height = bimg.getHeight();
PDPage page = new PDPage(new PDRectangle(width, height));
document.addPage(page);
PDImageXObject pdimg = LosslessFactory.createFromImage(document, bimg);
PDPageContentStream stream = new PDPageContentStream(document, page, PDPageContentStream.AppendMode.APPEND, true);
stream.drawImage(pdimg, 0, 0);
stream.close();

document.save(filename);
document.close();

And here is the result:

enter image description here

As you can see the PDF image is more "pale" (saturation? - sorry, I'm not good at color theory and don't know how to name it correctly).

What I have found out:

  1. Printing BufferedImage to JLabel using JLabel(new ImageIcon(bimg)) constructor produces the same result as with PDF ("pale" colors) so I guess PDFBox is not the reason.
  2. Changing scanning resolution - no effect.
  3. bimg.getTransparency() returns 1 (OPAQUE)
  4. bimg.getType() returns 0 (TYPE_CUSTOM)

PNG file:

http://s000.tinyupload.com/index.php?file_id=95648202713651192395

PDF file

http://s000.tinyupload.com/index.php?file_id=90369236997064329368

Shoer answered 27/5, 2016 at 8:21 Comment(6)
so what is the correct one? the png or the pdf?Direct
@Direct Png is correct.Shoer
@TilmanHausherr Updated question with the links.Shoer
@VladimirM. What does getColorModel() return?Aria
@AbdulFatir ColorModel: #pixelBits = 24 numComponents = 3 color space = java.awt.color.ICC_ColorSpace@19481b2 transparency = 1 has alpha = false isAlphaPre = falseShoer
@VladimirM. I can't help, sorry. Please do also ask a question at jfreesane. github.com/sjamesr/jfreesane/issues . Basically, your problem is that the image is bad when you get it, but when you save and reload it, it is good.Ics
S
1

There was an issue in JFreeSane with colorspaces, it was fixed in version 0.97:

https://github.com/sjamesr/jfreesane/releases/tag/jfreesane-0.97

Shoer answered 22/8, 2016 at 6:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.