• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to print an RenderedImage?

 
Greenhorn
Posts: 10
Netbeans IDE Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

-Problem Context-
I've build an applet to properly manipulate and visualize TIFF images in browsers (manipulate means to rotate, zoom, an multitiff support). The applet receive base64 string representation of the TIFF image and show it to the user properly using JAI API. The applet keep the image without any transformation (as a RenderedImage), and all operations (rotate, zoom) are kept in another Object (RenderedOp).

-Problem-
I want to implement a print function that allows the user to print the TIFF image kept in the applet, but when i print the image, only a portion of the image is printed because the image is to big. I tried to scale the image to fit the page size, but when printed, the image is not showed properly (image lost quality). After that, i tried to save the image into a file, to check if the image, when coded and decoded to a Base64 string representation, was losing quality. After save the image, i printed it using an image viewer (Ubuntu Image Viewer is the one i am using), but when printed from the image viewer, the printout was correct (the image was fitted in the paper without lose quality).

-Question-
¿How can i print an image bigger than paper size without lose quality?
¿Am i doing the wrong operation to the image to fit the page? (scale operation in this case).

Below i put the code of the print method (implemented in a Printable Object) that is used to print the image. In this code the image is scale to fit the page.

-Code-


Any comments or suggestions are welcome. Thanks in advance for your help.
 
Alvaro Quintana
Greenhorn
Posts: 10
Netbeans IDE Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, after a lot of work i've discover that the printout image has poor quality because PrintJob Object by default set page dimension for 72 DPI. Now my problem is to properly change that value. Below i show the code i'm using to do it, but is not working.

Now the real problem for me is to properly change DPI attribute ..

Thanks in advance,
 
Alvaro Quintana
Greenhorn
Posts: 10
Netbeans IDE Fedora Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Problem Solved!

-¿What was wrong?-
I was scaling the image (RenderedImage) Object.

-Solution-
Keep the original image (without scale) and scale the Graphics2D object before draw image on it. After that the image is automatically adjusted to Graphics2D object and correctly printed (using best DPI configuration). Below i add the correct code to properly print an RenderedImage Object.





Hope this help!!
reply
    Bookmark Topic Watch Topic
  • New Topic