使用Java原生Graphics2D给Activiti流程当前环节加上红色边框。

近期在在项目中用到了Activiti做流程管理,在当前环节中要求画上边框,最出使用的是CSS或JS的方式做的,可是后来发现IMG标签大小变了后,或者弹出页里面的流程图不一致导致边框错位。IE6和IE其它版本中的圆角和兼容性还是有问题,于是我用Java原生Graphics2D的方式画上了边框,并增加了圆角。


现在将原代码公开,方便大家使用。


上个效果图:



代码如下:

/**
	 * 
	 * <br/>Description:给Activiti绘制流程环节矩形框
	 * <p>Author:Eric Shi/史丙利</p>
	 * @param is
	 * @param response
	 * @param x
	 * @param y
	 * @param width
	 * @param height
	 * @throws FileNotFoundException
	 * @throws IOException
	 */
	public void drawRect(InputStream is,HttpServletResponse response,int x, int y, int width, int height) throws FileNotFoundException,IOException{
		try{
			BufferedImage buffImg = ImageIO.read(is);  

			Graphics2D g2d = buffImg.createGraphics();
			
			g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);  
			
			g2d.setColor(Color.red);
			BasicStroke wideStroke = new BasicStroke(1.5f);
			g2d.setStroke(wideStroke);

			g2d.drawRoundRect(x,y,width,height,22,22);
			ServletOutputStream sos=response.getOutputStream();
			ImageIO.write(buffImg,"jpeg",response.getOutputStream());
			
			sos.close();
			sos.flush();
			
		}catch(FileNotFoundException e){
			e.printStackTrace();
		}catch(IOException e){
			e.printStackTrace();
		}
	}



转载于:https://my.oschina.net/eriloanjoan/blog/717561

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值