在java中打印具有实际大小的图像 [英] print a image with actual size in java
本文介绍了在java中打印具有实际大小的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一张照片,我想在纸上以实际尺寸打印并在代码下方实现,但我不知道为什么这段代码缩放图片但我希望图片保持其大小,请你帮我?
well i have a picture and i want to print it in exactly actual size on paper and implemented below code but i don't know why this code zooms the picture but i want picture to keep its size , could you please help me ?
非常感谢...
final Image img = new ImageIcon("C:\\check.jpg").getImage();
PrinterJob printJob = PrinterJob.getPrinterJob();
printJob.setPrintable(new Printable()
{
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException {
if (pageIndex != 0) {
return NO_SUCH_PAGE;
}
graphics.drawImage(img, 0, 0, img.getWidth(null), img.getHeight(null), null);
return PAGE_EXISTS;
}
});
if (printJob.printDialog()) {
try {
printJob.print();
} catch (Exception prt) {
System.err.println(prt.getMessage());
}
}
推荐答案
那可能是因为您的图像没有正确的分辨率。谷歌每英寸点数或图像分辨率,然后看一下 PageFormat ,显然使用72 dpi的分辨率。现在您应该有足够的信息来正确缩放图像。
That is probably because your image does not have the correct resolution. Google "dots per inch" or "image resolution," then take a look at the javadoc for PageFormat which obviously uses a resolution of 72 dpi. Now you should have enough information to scale your image correctly.
这篇关于在java中打印具有实际大小的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文