CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: How to print images correctly

  1. #1
    Join Date
    Apr 2014
    Posts
    3

    Question How to print images correctly

    Hi ALL,

    I'm trying to print (to the printer) a small image 265x35 px and it is printed in very poor quality with jagged edges.
    When I'm printing it from any other program (e.g. Word, mspaint, etc) it is printed clearly.

    Also, the image is printed bigger than it's normal size (approximately 25%). But, I'm not doing any scale in my code.
    I did scaled it down to the right size, but the quality still remained very poor and jadged.

    The image is a transparent PNG file. I tried with a BMP too, but I got the same results.

    I'm using

    Code:
    Graphics g; 
    g.drawImage(headerLogo, x, y, headerLogo.getWidth(), headerLogo.getHeight(), imageObserver);
    What may be wrong ?

  2. #2
    Join Date
    Apr 2014
    Posts
    3

    Re: How to print images correctly

    OK, this is getting seriously annoying...

    I'm struggling to print an image in its original size and quality.

    I tried this time to design my logo (png image) with 150ppi resolution (instead of 72ppi before). I printed it from mspaint and Photoshop and prints crystal clear and in right dimensions.

    I printed from Java (using the code above) and it prints bigger and in poor guality.

    I figured out (simple math) that java prints by 75% bigger any graphic than it's real size. I scale it down by

    Code:
    g2d.drawImage(headerLogo, x, y, headerLogo.getWidth() * 75/100, headerLogo.getHeight() * 75/100, imageObserver);
    and using these rentering hints

    Code:
    g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    But the result is really really disappointing!

    What am I doing wrong ?

  3. #3
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: How to print images correctly

    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)