| | |
| | | // try { |
| | | // DrawingUtil.drawImage("D:\\IDEA\\spax_alibaba\\spax_alibaba_user\\src\\main\\resources\\static\\ca1.jpg", |
| | | // "D:\\IDEA\\spax_alibaba\\spax_alibaba_user\\src\\main\\resources\\static\\ca.jpg","D:\\IDEA\\spax_alibaba\\spax_alibaba_user\\src\\main\\resources\\static\\1.jpg" |
| | | // ,"张三", |
| | | // ,"张三", |
| | | // "123456", |
| | | // "深圳市保安员资格考试", |
| | | // "深圳市保安员资格考试", |
| | | // "123456", |
| | | // "666", |
| | | // "圆融教育考试中心(深圳)", |
| | | // "圆融教育考试中心(深圳)考场16", |
| | | // "71区兴东众里创业社区3~5楼五楼502", |
| | | // "地铁5号线兴东站D出口(右转直行100米到达建设" + |
| | | // "工业园J栋兴东众里创业社区);驾车:导航" + |
| | | // "(圆融考试中心)可直达考场。无提供车位," + |
| | | // "建议公共交通出行。", |
| | | // "圆融教育考试中心(深圳)", |
| | | // "圆融教育考试中心(深圳)考场16", |
| | | // "71区兴东众里创业社区3~5楼五楼502", |
| | | // "地铁5号线兴东站D出口(右转直行100米到达建设" + |
| | | // "工业园J栋兴东众里创业社区);驾车:导航" + |
| | | // "(圆融考试中心)可直达考场。无提供车位," + |
| | | // "建议公共交通出行。", |
| | | // "2016-02-02 9:00", |
| | | // "2016-02-02 9:00", |
| | | // "男"); |
| | | // "男"); |
| | | // } catch (Exception e) { |
| | | // e.printStackTrace(); |
| | | // } |
| | | } |
| | | /** |
| | | * @param img 图片路径 |
| | | * @param sImg СͼƬ 980x994 |
| | | * @param name, 姓名 |
| | | * @param card, 号码 |
| | | * @param cname, 科目 |
| | | * @param number, 证号 |
| | | * @param ID, 座位 |
| | | * @param sitename, 考站名称 |
| | | * @param ename, 考场名称 |
| | | * @param address, 考场地址 |
| | | * @param traffic, 考点交通 |
| | | * @param starttime, 开始 |
| | | * @param endtime 结束 |
| | | * @param sex 性别 |
| | | * @param img 图片路径 |
| | | * @param sImg 小图片 980x994 |
| | | * @param name, 姓名 |
| | | * @param card, 号码 |
| | | * @param cname, 科目 |
| | | * @param number, 证号 |
| | | * @param ID, 座位 |
| | | * @param sitename, 考站名称 |
| | | * @param ename, 考场名称 |
| | | * @param address, 考场地址 |
| | | * @param traffic, 考点交通 |
| | | * @param starttime, 开始 |
| | | * @param endtime 结束 |
| | | * @param sex 性别 |
| | | * */ |
| | | public static void drawImage(String img, |
| | | String sImg, |
| | |
| | | String sex, |
| | | OutputStream outputStream |
| | | ) throws Exception { |
| | | //读入图片到内存 |
| | | //读入图片到内存 |
| | | InputStream is = DrawingUtil.class.getClassLoader().getResourceAsStream(img); |
| | | //创建JPEG解码器 |
| | | //创建JPEG解码器 |
| | | BufferedImage bufferImg = ImageIO.read(is); |
| | | // JPEGImageDecoder jpegDecoder = JPEGCodec.createJPEGDecoder(is); |
| | | //获取缓冲数据流 |
| | | //获取缓冲数据流 |
| | | // BufferedImage bufferImg = jpegDecoder.decodeAsBufferedImage(); |
| | | //得到画笔对象 |
| | | //得到画笔对象 |
| | | Graphics g = bufferImg.getGraphics(); |
| | | |
| | | /*创建附加的小图片对象*/ |
| | | /*创建附加的小图片对象*/ |
| | | // ClassPathResource classP = new ClassPathResource(sImg); |
| | | // ImageIcon imgIcon=new ImageIcon(classP.getURL()); |
| | | // //得到Image对象 |
| | | // //得到Image对象 |
| | | // Image simg =imgIcon.getImage(); |
| | | // //将小图片绘到大图片上,位置信息:(x,y) |
| | | // //将小图片绘到大图片上,位置信息:(x,y) |
| | | // g.drawImage(simg,1241,433,null); |
| | | |
| | | |
| | | //设置字体颜色 |
| | | //设置字体颜色 |
| | | g.setColor(new Color(78,76,75));//78,76,75 |
| | | //字体、字体大小 |
| | | Font f = new Font("微软雅黑", Font.PLAIN, 38); |
| | | //字体、字体大小 |
| | | Font f = new Font("微软雅黑", Font.PLAIN, 38); |
| | | g.setFont(f); |
| | | //图片上绘制字符串内容,位置信息(x,y) |
| | | //图片上绘制字符串内容,位置信息(x,y) |
| | | g.drawString(name, 500,489); |
| | | g.drawString(card, 500, 561); |
| | | g.drawString(cname, 500,629); |
| | |
| | | g.drawString(endtime, 500, 1405); |
| | | g.drawString(sex, 1081,489); |
| | | g.dispose(); |
| | | // //输出新图片 |
| | | // //输出新图片 |
| | | // OutputStream out = new FileOutputStream(nImg); |
| | | //解析内存中的图像数据 |
| | | //解析内存中的图像数据 |
| | | // JPEGImageEncoder en = JPEGCodec.createJPEGEncoder(outputStream); |
| | | // en.encode(bufferImg); |
| | | ImageIO.write(bufferImg, "jpeg", outputStream); |
| | | |
| | | //关闭流 |
| | | //关闭流 |
| | | is.close(); |
| | | // out.close(); |
| | | } |
| | | |
| | | /** |
| | | * 根据宽度自动换行 |
| | | * @param fontSize 字体大小 |
| | | * @param beginX 开始X |
| | | * @param beginY 开始Y |
| | | * @param imgWidth 区域宽度 |
| | | * @param rowSpacing 行距 |
| | | * @param g 画笔 |
| | | * @param text 文本 |
| | | * 根据宽度自动换行 |
| | | * @param fontSize 字体大小 |
| | | * @param beginX 开始X |
| | | * @param beginY 开始Y |
| | | * @param imgWidth 区域宽度 |
| | | * @param rowSpacing 行距 |
| | | * @param g 画笔 |
| | | * @param text 文本 |
| | | */ |
| | | public static void drawText(int fontSize,int beginX,int beginY,int imgWidth,int rowSpacing,Graphics g,String text){ |
| | | //文字叠加,自动换行叠加 |
| | | //文字叠加,自动换行叠加 |
| | | int tempX = beginX ; |
| | | int tempY = beginY ; |
| | | int tempCharLen = 0;//单字符长度 |
| | | int tempLineLen = 0;//单行字符总长度临时计算 |
| | | int tempCharLen = 0;//单字符长度 |
| | | int tempLineLen = 0;//单行字符总长度临时计算 |
| | | StringBuffer sb = new StringBuffer(); |
| | | int textMaxWidth = imgWidth - 10; |
| | | for (int i = 0; i < text.length(); i++) { |
| | |
| | | tempCharLen = g.getFontMetrics(g.getFont()).charWidth(tempChar); |
| | | tempLineLen += tempCharLen; |
| | | if (tempLineLen >= textMaxWidth) { |
| | | //长度已经满一行,进行文字叠加 |
| | | //长度已经满一行,进行文字叠加 |
| | | g.drawString(sb.toString(), tempX, tempY); |
| | | sb.delete(0, sb.length());//清空内容,重新追加 |
| | | sb.delete(0, sb.length());//清空内容,重新追加 |
| | | tempY += (fontSize + rowSpacing); |
| | | tempLineLen = 0; |
| | | } |
| | | sb.append(tempChar);//追加字符 |
| | | sb.append(tempChar);//追加字符 |
| | | } |
| | | g.drawString(sb.toString(), tempX, tempY);//最后叠加余下的文字 |
| | | g.drawString(sb.toString(), tempX, tempY);//最后叠加余下的文字 |
| | | } |
| | | } |