0

I'm trying to save snapshots of my JPanel as .png files. The problem is that the image I can create is 96DPI by default. Since this pictures have to be printed, I'd need an higher level of quality. Is there any way I can improve my image quality? Are there maybe smarter ways for taking snapshots of a JPanel? You can find herein attached part of my code, where the variable "c" stands for the JPanel. Thanks in advance.

//c stands for my JPanel    
BufferedImage im = new BufferedImage(c.getWidth(), c.getHeight(), BufferedImage.TYPE_INT_ARGB);

//calculate x,y,width and height basing on the particular image crop I want to get 
int x = roundToInt(cropFrame.getX()*panel.getScale()+groupPathways_layout.getX()-viewArea_data.getX());
int y = roundToInt(cropFrame.getY()*panel.getScale()+groupPathways_layout.getY()-viewArea_data.getY());
int w = roundToInt(cropFrame.getWidth()*panel.getScale());
int h = roundToInt(cropFrame.getHeight()*panel.getScale());

c.paint(im.getGraphics());

BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
bi.getGraphics().drawImage(im, 0, 0, w, h, x, y, x + w, y + h, null);

ImageIO.write(bi, "png", new File(path+"/"+name+imageFormat));
Roberto
  • 243
  • 1
  • 5
  • 15
  • If you _must_ [upsample](https://en.wikipedia.org/wiki/Upsampling), choose the optimal interpolation type, as suggested in this possible [duplicate](http://stackoverflow.com/q/4216123/230513). – trashgod Oct 02 '15 at 15:00
  • The post you mentioned, if I have well understood, deals about scaling the image and, unfortunately, with all the solutions proposed I have a loss in Image definition. There isn't a way to improve quality without changing image size, is there? – Roberto Oct 02 '15 at 15:43
  • 1
    At the higher resolution, were would the new pixels come from if not upampling? Please edit your question to include a [complete example](http://stackoverflow.com/help/mcve) that exhibits the problem you describe.; in your example, access posted images via `URL`, as shown [here](http://stackoverflow.com/a/10862262/230513); use synthetic images as shown [here](http://stackoverflow.com/a/15982915/230513); or use `UIManager` icons, as shown [here](http://stackoverflow.com/a/12228640/230513). – trashgod Oct 02 '15 at 15:59
  • 1
    See also [*The Myth of DPI*](http://www.webdesignerdepot.com/2010/02/the-myth-of-dpi/) and [*Setting DPI for PNG files*](http://stackoverflow.com/q/1551532/230513). – trashgod Oct 03 '15 at 07:58

0 Answers0