在我的应用程序中,以下代码打印卡片的正面和背面。在虚拟打印机(如 Virtual PDF 打印机、ImagePrinter Pro 和 Microsoft XPS Document Writer)上,输出是正确的。但是当我在真正的打印机上测试它时,它只打印了一半宽度的图像,而且高度是正确的。我用 A4 和 Letter 格式进行了测试,但一切都在风向标。不知道有什么问题。
public int print(Graphics g, PageFormat pageFormat, int pageIndex) {
Graphics2D g2d = (Graphics2D) g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING,
RenderingHints.VALUE_COLOR_RENDER_QUALITY);
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
g2d.setRenderingHint(RenderingHints.KEY_RENDERING,
RenderingHints.VALUE_RENDER_QUALITY);
g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BICUBIC);
int w = 360, h = 240;
int padding = 2;
BufferedImage temp = new BufferedImage(w * 2, h, BufferedImage.TYPE_INT_ARGB);
Graphics2D tempG = temp.createGraphics();
tempG.drawImage(card.getFrontImage(), 0, 0,
w, h, null);
tempG.drawImage(card.getBackImage(), w, 0,
w, h, null);
tempG.dispose();
g2d.drawImage(temp, (int) 0, 0 + padding,
(int) pageFormat.getImageableWidth(), (int) pageFormat.getImageableHeight()/5, null);
}
有什么帮助吗?