当我打印图像时,它似乎放大了结果页面。但是,当我们尝试将图像保存到文件时,会有正常的缩放。
如何以原始比例打印图像?
有一个示例代码:
@Override
public int print(Graphics graphics, PageFormat pageFormat, int page) throws PrinterException {
if(page < sequence.size()) {
BufferedImage image = sequence.get(page).getImage();
String filename = ((Integer)page).toString()+".png";
File outputFile = new File(filename);
try {
ImageIO.write(image, "png", outputFile);
} catch (IOException e) {
e.printStackTrace();
}
graphics.drawImage(image, (int)pageFormat.getImageableX(), (int)pageFormat.getImageableY(), null);
return PAGE_EXISTS;
} else {
return NO_SUCH_PAGE;
}
}