好记忆不如烂笔头,能记下点东西,就记下点,有时间拿出来看看,也会发觉不一样的感受.
如图是我的信用 , 在页面上的展示
要生成报告,因为html在处理上失真了,所以只能是按照图片进行位移了。
图一
图二
利用这两张图的位移来实现如上图的展示.
结果如图所示:图三
具体实现:计算出图一的图片的长度,根据评级的CR1....CR7 的位置,计算出位移大小,把图二的红标移动到对应的位移上,就形成了图三的图。具体代码如下,可以做参照,
/** * 获得CR 的报告信息 * @param crResult * @param pdfPropsConfig * @param reportType * @param creditCode * @return */ public static String getImage(CRResult crResult,PdfPropsConfig pdfPropsConfig,String reportType, String creditCode){ String AAstr = crResult.getAA(); String creditgrade = crResult.getCrLevel(); if(StringUtils.isNotBlank(creditgrade)){ Double grade = Double.parseDouble(AAstr); int point=getPointx(grade,creditgrade); try { String srcPath = pdfPropsConfig.getImgUrl()+CommonUtils.getSplit() + "cr_img.png"; String pointimg = pdfPropsConfig.getImgUrl()+CommonUtils.getSplit()+ "crpoint_img.png"; // 上传文件路径 String destFile=pdfPropsConfig.getDataPath()+CommonUtils.getSplit()+reportType+CommonUtils.getSplit()+creditCode+CommonUtils.getSplit(); String fileName = creditCode + ".png" ; destFile = destFile + fileName; File df=new File(destFile); if (!df.getParentFile().exists()){ df.getParentFile().mkdirs(); }if (!df.exists()){ df.createNewFile(); } convertImageAddPoint(srcPath,pointimg,destFile,point); return destFile; } catch (Exception e) { e.printStackTrace(); } } return null; } /** * 分数和信用等级瞄点. * @param grade * @param creditgrade:cr1,cr2,cr3,cr4,cr5,cr6,cr7 * @return */ private static int getPointx(Double grade,String creditgrade){ int cr1xlenth=4; int cr2xlenth=24; int cr3xlenth=49; int cr4xlenth=100; int cr5xlenth=55; int cr6xlenth=13; int cr7xlenth=28; int x=0; if(grade!=null && StringUtils.isNotBlank(creditgrade)){ if(StringUtils.equals(creditgrade,"CR1")){ x=cr1xlenth; }else if(StringUtils.equals(creditgrade,"CR2")){ x=cr2xlenth+cr1xlenth; }else if(StringUtils.equals(creditgrade,"CR3")){ x=cr3xlenth+cr1xlenth+cr2xlenth; }else if(StringUtils.equals(creditgrade,"CR4")){ x=cr4xlenth+cr1xlenth+cr2xlenth+cr3xlenth; }else if(StringUtils.equals(creditgrade,"CR5")){ x=cr5xlenth+cr1xlenth+cr2xlenth+cr3xlenth+cr4xlenth; }else if(StringUtils.equals(creditgrade,"CR6")){ x=cr6xlenth+cr1xlenth+cr2xlenth+cr3xlenth+cr4xlenth+cr5xlenth; }else if(StringUtils.equals(creditgrade,"CR7")){ x=cr7xlenth+cr1xlenth+cr2xlenth+cr3xlenth+cr4xlenth+cr5xlenth+cr6xlenth; } x=x-36+7; } return x; } /** * 处理图片,将pointimg固定原图片上,并生产新的图片 * @param srcPath * @param pointimg * @param destFile */ public static void convertImageAddPoint(String srcPath,String pointimg,String destFile,int x){ try { BufferedImage big = ImageIO.read(new File(srcPath)); Graphics2D gd = big.createGraphics(); gd.setBackground(Color.white); BufferedImage small = ImageIO.read(new File(pointimg)); int y = 2; gd.drawImage(small, x, y, small.getWidth(), small.getHeight(), null); //在图形和图像中实现混合和透明效果 gd.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP,1)); gd.dispose(); ImageIO.write(big, "png", new File(destFile)); } catch (Exception e) { e.printStackTrace(); } }
如此操作完成之后,就可以实现图三的效果。