java设置图像的分辨率和打印尺寸 [英] java setting resolution and print size for an Image

查看:863
本文介绍了java设置图像的分辨率和打印尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个程序,该程序生成一个BufferedImage,该BufferedImage将在屏幕上显示然后打印.图像的一部分包括1像素宽的网格线.即,线是1个像素,线之间大约有10个像素.由于屏幕分辨率的原因,显示的图像要大得多,每行有几个像素.我想将其绘制得更小,但是当我缩放图像(通过使用Image.getScaledInstance或Graphics2D.scale)时,我失去了大量的细节.

I wrote a program that generates a BufferedImage to be displayed on the screen and then printed. Part of the image includes grid lines that are 1 pixel wide. That is, the line is 1 pixel, with about 10 pixels between lines. Because of screen resolution, the image is displayed much bigger than that, with several pixels for each line. I'd like to draw it smaller, but when I scale the image (either by using Image.getScaledInstance or Graphics2D.scale), I lose significant amounts of detail.

我也想打印图像,并且正在处理相同的问题.在这种情况下,我将使用以下代码来设置分辨率:

I'd like to print the image as well, and am dealing with the same problem. In that case, I am using this code to set the resolution:

HashPrintRequestAttributeSet set = new HashPrintRequestAttributeSet();
PrinterResolution pr = new PrinterResolution(250, 250, ResolutionSyntax.DPI);
set.add(pr);
job.print(set);

可以使图像变小而不丢失细节.但是问题是,图像在相同的边界处被切除,就像我没有设置分辨率一样.我也很困惑,因为我希望有更多的DPI可以制作出较小的图像,但它却以其他方式起作用.

which works to make the image smaller without losing detail. But the problem is that the image is cut off at the same boundary as if I hadn't set the resolution. I'm also confused because I expected a larger number of DPI to make a smaller image, but it's working the other way.

我在带eclipse的Windows 7上使用Java 1.6.

I'm using java 1.6 on Windows 7 with eclipse.

推荐答案

关于在页面边界上被切除的图像,您是否检查了图形的裁剪区域?我的意思是尝试:

Regarding the image being cut-off on the page boundary, have you checked the clip region of the graphics? I mean try :

System.out.println(graphics.getClipBounds());

并确保已正确设置.

这篇关于java设置图像的分辨率和打印尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆