long beginTime = System.currentTimeMillis();int width = 560;int height = 250;//绘制的图片的大小BufferedImage image = new BufferedImage(width, height,BufferedImage.TYPE_INT_BGR); //创建画布Graphics graphics = image.createGraphics();graphics.setColor(Color.WHITE);//设置大小graphics.fillRect(0, 0, width, height);graphics.setColor(Color.BLACK);//斜体Font.LAYOUT_NO_START_CONTEXTgraphics.setFont(new Font("宋体", Font.LAYOUT_LEFT_TO_RIGHT, 12));try {//读取文件String uri = "udtfile/8607/P05.000000.8607";File file = new File(uri);//List lists = FileUtils.readLines(file, "GBK");//文件流List lists = IOUtils.readLines(new FileInputStream(file), "GBK");lists.remove(0);// lists.remove(0);//在固定位置绘制图片//小图片的路径 可以放一个byteImageIcon imgIcon = new ImageIcon("D:/temp/temp.jpg"); //得到Image对象。 Image img = imgIcon.getImage(); //将小图片绘到大图片上。 //5,300 .表示你的小图片在大图片上的位置。 graphics.drawImage(img, 310, 75, 110, 110, null);//设置颜色。 graphics.setColor(Color.BLACK); for (int i = 0; i < lists.size(); i++) {graphics.drawString(lists.get(i), 2, 12*i);}graphics.dispose();//ByteArrayOutputStream out = new ByteArrayOutputStream();//boolean flag = ImageIO.write(image, "JPEG", out);//byte[] binaryData = out.toByteArray();//String base64BYTE = org.apache.commons.net.util.Base64.encodeBase64String(binaryData);ImageIO.write(image, "JPEG", new File("D:/temp/qwer.jpg"));System.out.println("生图片成功");long endTime = System.currentTimeMillis();long times = endTime - beginTime;System.out.println(times);构建打印请求属性集 //HashPrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();设置打印格式,因为未确定类型,所以选择autosense //DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE; 定位默认的打印服务 //PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService(); //DocPrintJob job = defaultService.createPrintJob(); //创建打印作业 //DocAttributeSet das = new HashDocAttributeSet();//Doc doc = new SimpleDoc(new FileInputStream(new File("D:/qwer.jpg")), flavor, das); //job.print(doc, pras); } catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}
java绘图片_java 图片绘制
最新推荐文章于 2024-06-15 16:25:56 发布