当前位置: 技术问答>java相关
请问怎样才能提高打印的分辨率?
来源: 互联网 发布时间:2017-04-29
本文导语: 我们目前已经在应用程序中实现了打印功能,可是无论是打印预览,还是真实打印出来的效果都非常让人不满意,请高手指点,要怎么样才能提高打印效果!本人非常感谢! | 是doubleButtering的...
我们目前已经在应用程序中实现了打印功能,可是无论是打印预览,还是真实打印出来的效果都非常让人不满意,请高手指点,要怎么样才能提高打印效果!本人非常感谢!
|
是doubleButtering的问题
RepaintManager currentManager = RepaintManager.currentManager(this);
currentManager.setDoubleBufferingEnabled(false);
this.paint(g2);
currentManager.setDoubleBufferingEnabled(true);
关于doubleBuffering的含义:
The Role of Double Buffering
With Java Swing, almost all components have double buffering turned on by default. In general, this is a great boon, making for convenient and efficient paintComponent method. However, in the specific case of printing, it can be a huge problem. First, since printing components relies on scaling the coordinate system and then simply calling the component's paint method, if double buffering is enabled printing amounts to little more than scaling up the buffer (off-screen image). This results in ugly low-resolution printing like you already had available. Secondly, sending these huge buffers to the printer results in huge print spooler files which take a very long time to print.
Consequently, you need to make sure double buffering is turned off before you print. If you have only a single JPanel or other JComponent, you can call setDoubleBuffered(false) on it before calling the paint method, and setDoubleBuffered(true) afterwards. However, this suffers from the flaw that if you later nest another container inside, you're right back where you started from. A much better solution is to globally turn off double buffering via
RepaintManager currentManager =
RepaintManager.currentManager(c);
currentManager.setDoubleBufferingEnabled(false);
and then to re-enable it after calling paint via the setDoubleBufferingEnabled(true). (Thanks to Bob Evans for suggesting RepaintManager instead of the much uglier recursive descent method I was using to globally disable and re-enable double buffering.) Although this will completely fix the problem with low-resolution printouts, if the components have large, complex filled backgrounds you can still get big spool files and slow printing.
原文见
http://www.apl.jhu.edu/~hall/java/Swing-Tutorial/Swing-Tutorial-Printing.html
RepaintManager currentManager = RepaintManager.currentManager(this);
currentManager.setDoubleBufferingEnabled(false);
this.paint(g2);
currentManager.setDoubleBufferingEnabled(true);
关于doubleBuffering的含义:
The Role of Double Buffering
With Java Swing, almost all components have double buffering turned on by default. In general, this is a great boon, making for convenient and efficient paintComponent method. However, in the specific case of printing, it can be a huge problem. First, since printing components relies on scaling the coordinate system and then simply calling the component's paint method, if double buffering is enabled printing amounts to little more than scaling up the buffer (off-screen image). This results in ugly low-resolution printing like you already had available. Secondly, sending these huge buffers to the printer results in huge print spooler files which take a very long time to print.
Consequently, you need to make sure double buffering is turned off before you print. If you have only a single JPanel or other JComponent, you can call setDoubleBuffered(false) on it before calling the paint method, and setDoubleBuffered(true) afterwards. However, this suffers from the flaw that if you later nest another container inside, you're right back where you started from. A much better solution is to globally turn off double buffering via
RepaintManager currentManager =
RepaintManager.currentManager(c);
currentManager.setDoubleBufferingEnabled(false);
and then to re-enable it after calling paint via the setDoubleBufferingEnabled(true). (Thanks to Bob Evans for suggesting RepaintManager instead of the much uglier recursive descent method I was using to globally disable and re-enable double buffering.) Although this will completely fix the problem with low-resolution printouts, if the components have large, complex filled backgrounds you can still get big spool files and slow printing.
原文见
http://www.apl.jhu.edu/~hall/java/Swing-Tutorial/Swing-Tutorial-Printing.html
|
我大概看了一下java.awt.print的内容,好像打印功能只有一个分辨率1/72英寸,这跟屏幕上的像素是一致的,这样的分辨率是不可能有很高的打印效果的。
做过Windows编程的人都知道可以通过SetMapMode来指定自己所需要的分辨率的。
我也不知道java是否提供对更高分辨率的支持,反正我没找到。
做过Windows编程的人都知道可以通过SetMapMode来指定自己所需要的分辨率的。
我也不知道java是否提供对更高分辨率的支持,反正我没找到。