2016-05-27 34 views
6

jfreesane ve Apache PDFBox kullanarak basit bir tarama uygulaması yazıyorum.BufferedImage renk doygunluğu

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(); 

Ve yapma PDF:

enter image description here

PDF resmini görebileceğiniz gibi: Burada

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(); 

Ve sonucudur İşte

tarama kodudur daha "solgun" mu (doygunluk?) - üzgünüm, renk teorisinde iyi değilim ve bilmiyorum doğru şekilde nasıl adlandırılır).

ben öğrendim Ne:

PDFBox olan JLabel (yeni ImageIcon (bimg)) yapıcı PDF ile aynı sonucu üretir kullanarak JLabel için
  • Baskı BufferedImage ("soluk" renkler) yüzden sanırım
      sebep değil.
    1. Tarama çözünürlüğünü değiştirme - etki yok.

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

      PDF dosyası

      :

    2. bimg.getTransparency() 1 (OPAK)
    3. bimg.getType() döndürür 0 (TYPE_CUSTOM)

    PNG dosyası döndürür http://s000.tinyupload.com/index.php?file_id=90369236997064329368

  • +0

    yüzden doğru olan ne için: JFreeSane sorunu colorspaces ile, bu sürümde 0.97 giderilmiştir? png veya pdf? – gpasch

    +0

    @gpasch Png doğru. –

    +0

    @TilmanHausherr Bağlantılı güncel soru. –

    cevap