Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3794802
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:59:07+00:00 2026-05-19T12:59:07+00:00

I have an application that I want to export high-resolution (or rather, high pixel

  • 0

I have an application that I want to export high-resolution (or rather, high pixel density?) images for printing – for example, I want images that print at 250 dots per inch (DPI), instead of the default, which I understand to be 72 DPI.

I’m using a BufferedImage with a Graphics2D object to draw the image, then ImageIO.write() to save the image.

Any idea how I can set the DPI?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T12:59:08+00:00Added an answer on May 19, 2026 at 12:59 pm

    Kurt’s answer showed the way, still it took me quite some time to get it run, so here is the code that sets DPI when saving a PNG. There is a lot to do to get the proper writers and such…

     private BufferedImage gridImage;
     ...
    
     private void saveGridImage(File output) throws IOException {
        output.delete();
    
        final String formatName = "png";
    
        for (Iterator<ImageWriter> iw = ImageIO.getImageWritersByFormatName(formatName); iw.hasNext();) {
           ImageWriter writer = iw.next();
           ImageWriteParam writeParam = writer.getDefaultWriteParam();
           ImageTypeSpecifier typeSpecifier = ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB);
           IIOMetadata metadata = writer.getDefaultImageMetadata(typeSpecifier, writeParam);
           if (metadata.isReadOnly() || !metadata.isStandardMetadataFormatSupported()) {
              continue;
           }
    
           setDPI(metadata);
    
           final ImageOutputStream stream = ImageIO.createImageOutputStream(output);
           try {
              writer.setOutput(stream);
              writer.write(metadata, new IIOImage(gridImage, null, metadata), writeParam);
           } finally {
              stream.close();
           }
           break;
        }
     }
    
     private void setDPI(IIOMetadata metadata) throws IIOInvalidTreeException {
    
        // for PMG, it's dots per millimeter
        double dotsPerMilli = 1.0 * DPI / 10 / INCH_2_CM;
    
        IIOMetadataNode horiz = new IIOMetadataNode("HorizontalPixelSize");
        horiz.setAttribute("value", Double.toString(dotsPerMilli));
    
        IIOMetadataNode vert = new IIOMetadataNode("VerticalPixelSize");
        vert.setAttribute("value", Double.toString(dotsPerMilli));
    
        IIOMetadataNode dim = new IIOMetadataNode("Dimension");
        dim.appendChild(horiz);
        dim.appendChild(vert);
    
        IIOMetadataNode root = new IIOMetadataNode("javax_imageio_1.0");
        root.appendChild(dim);
    
        metadata.mergeTree("javax_imageio_1.0", root);
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web application that is becoming rather large. I want to separate
I have written a WPF application that I want to port to Silverlight 2.
I want to run javascript/Python/Ruby inside my application. I have an application that creates
I have built an application that uses SQL Express 2005 and I want to
I have this web application that has grown to an unmanageable mess. I want
I have a wxPython application that relies on an external config file. I want
Now that I know C++ I want to get into desktop application that have
i have a server - client application that runs on java 1.3; i want
I have a web server that runs my web application. If I want to
Assume that we have N erlang nodes, running same application. I want to share

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.