将Graphics2D绘制到另一个Graphics2D

问题描述:

是否可以从一个 Graphics2D 绘制到另一个 Graphics2D ?

It is possible to draw from one Graphics2D to another Graphics2D?

让我解释一下.我有打印问题,当我在屏幕上显示 JTextArea JTextPanel 时,内部会使用它的 sun.java2d.SunGraphics2D ,但是在即时打印时使用了 sun.print.PeekGraphics sun.awt.windows.WPathGraphics .问题出在某种字体上,例如Arial.在某些尺寸下,线被切掉.我尝试了很多方法来在打印中呈现文本,例如 Graphics2D.drawString SwingUtilities2.drawString TextLayout.drawString ,但是在某些情况下如果线条仍然被剪掉,或者线条没有被剪掉,但是某种理由使得空白消失了.

Let me explain. I have printing issues, when i display a JTextArea or JTextPanel in screen, internaly its used sun.java2d.SunGraphics2D, but when im printing its used sun.print.PeekGraphics and sun.awt.windows.WPathGraphics. The problem is with some kind of Fonts, like Arial. In some sizes lines are cut. I have tryed a lot of ways to render the text in printing, Graphics2D.drawString, SwingUtilities2.drawString, TextLayout.drawString, but in some cases lines are still cut, or lines are not cut but some kind of justification makes disapear white spaces.

所以我的想法是尝试使用sun.java2d.SunGraphics2D渲染组件,然后通过 sun.print.PeekGraphics sun.awt.windows.WPathGraphics将表面复制"到打印机.

So my idea is try to render components with sun.java2d.SunGraphics2D and "copy" the surface to the printer via sun.print.PeekGraphics or sun.awt.windows.WPathGraphics.

谢谢.

看起来您可以执行以下两项操作之一:

Looks like you can do one of two things:

  • 在图像上创建Graphics2D,进行渲染,然后将图像绘制到另一个Graphics2D

  • create a Graphics2D on an image, do your rendering, then draw the image into another Graphics2D

或使用Graphics.create()方法从原始Graphics2D创建Graphics2D,然后进行渲染.

or create Graphics2D from original Graphics2D using Graphics.create() methods and then do you rendering.