3
나는 한 묶음의 .jpg 이미지를 가지고 있으며 고정 된 크기 (cm)로 (잉크로 된 종이에) 인쇄하려고합니다. image1.png가 400x600 픽셀이고 300dpi로 인쇄하려고한다고 가정 해 보겠습니다. PrinterJob 및 Printable 구현을 사용해 보았지만 DPI를 지정할 수없는 것 같습니다. 여기 이 코드 조각입니다 : 페이지가 될 경우자바 - DPI로 이미지 인쇄
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintable(new PrintableDeck(cardDB));
PrintRequestAttributeSet attr = new HashPrintRequestAttributeSet();
attr.add(new PrinterResolution(300, 300, PrinterResolution.DPI));
attr.add(new MediaPrintableArea(8,21,210-16,296-42,MediaPrintableArea.MM));
attr.add(MediaSizeName.ISO_A4);
attr.add(new Copies(1));
attr.add(OrientationRequested.PORTRAIT);
attr.add(PrintQuality.HIGH);
//attr.add(Fidelity.FIDELITY_TRUE);
job.print(attr);
및
public class PrintableDeck implements Printable {
BufferedImage image;
public PrintableDeck(DB cardDB){
// This load an image into 'image'
BufferedImage image = cardDB.getCard(5462).getBufferedImage();
}
public int print(Graphics graphics, PageFormat pf, int page)
throws PrinterException{
if(page>0){
return NO_SUCH_PAGE;
}
Graphics2D g2 = (Graphics2D) graphics;
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g2.setRenderingHint(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_QUALITY);
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
double pageHeight = pf.getImageableHeight();
double pageWidth = pf.getImageableWidth();
// This print ONLY ~596x842, as if page is 72 DPI
System.out.println("Imageable WH: "+pageWidth+" x "+pageHeight);
// This print correctly 400x600
System.out.println("Image: "+images.get(0).getWidth(null)+" x "+images.get(0).getHeight(null));
g2.drawImage(image, 0, 0, null);
g2.dispose();
return PAGE_EXISTS;
}
}
를 위에서 볼 수 있듯이, 나는 ~ 595 PageFormat.getImageableHeight() ~ (842) 및 PageFormat.getImageableWidth()를 가지고 300 DPI, 나는이 값이 3000 x 2500 정도가 될 것으로 예상했다. 내가 누락 된 부분은 무엇입니까?
정말 고마워요.