0
回答
打印图片怎么实现啊,下面这个代码打印机怎么会没反应呢,谢谢啊
public class DrawImage {
public static void drawImage(String fileName){
try {
DocFlavor dof = null;
if(fileName.endsWith(".gif")){
dof = DocFlavor.INPUT_STREAM.GIF;
}
else if(fileName.endsWith(".jpg")){
dof = DocFlavor.INPUT_STREAM.JPEG;
}
else if(fileName.endsWith(".png")){
dof = DocFlavor.INPUT_STREAM.PNG;
}
FileInputStream fin = new FileInputStream(fileName);
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
pras.add(new Copies(1));
PrintService pss[] = PrintServiceLookup.lookupPrintServices(dof,pras);
if(pss.length == 0){
return ;
}
PrintService ps = pss[0];
System.out.println("Printing image...");
DocPrintJob job = ps.createPrintJob();
Doc doc = new SimpleDoc(fin,dof,null);
PrintService service = ServiceUI.printDialog(null, 50, 50, pss, ps, dof, pras);
if(service!=null){
job.print(doc, pras);
fin.close();
}
}catch(IOException ie){
ie.printStackTrace();
}catch(PrintException pe){
pe.printStackTrace();
}
}
public static void main(String[] args) {
drawImage(System.getProperty("user.dir") +File.separator+ "打磨前1.jpg");
}
}
<无标签>
举报
乔木
发帖于3年前 0回/191阅
顶部