图片裁剪 插件 crop4使用


http://www.js-css.cn/a/jscode/cutpic/2015/0517/1478.html


aa=$('.img-container > img');
bb=aa.cropper('getCroppedCanvas',{"width":60,"height":60});

var imgdata=bb.toDataURL("image/jpeg"); 获取图片流

imgdata.replace('data:image/jpeg;base64,','')


图片写入 

后台 

  public static void decodeBase64ToImage(String base64, String path,  String imgName) {
		  if(base64.indexOf(" ")>-1)
			  base64 = base64.replaceAll(" ", "+");
		  BASE64Decoder decoder = new BASE64Decoder();
		  
		  File folder = new File(path);
		  if (!folder.exists())
		  {
				folder.mkdirs();
		  }
			
		  try {
			  
			  FileOutputStream write = new FileOutputStream(new File(path+"/"+ imgName));
			  byte[] decoderBytes = decoder.decodeBuffer(base64);
			  write.write(decoderBytes);
			  write.close();
		  } 
		  catch (IOException e) 
		  {
			  e.printStackTrace();
		  }
	  }


使用 

	   String save_path=UploadUtil.img_head;
	    String imgName = System.currentTimeMillis() +".png";
	    String headImg_name=(String)request.getSession().getAttribute("headImg_name");
	    String imgdata="";
	    UploadUtil.decodeBase64ToImage(imgdata, save_path, imgName);


图片读取


	
	@RequestMapping("/image")
	@ResponseBody
	public void getImage(HttpServletRequest request, HttpServletResponse response) throws Exception{


	    String JPG="image/jpeg;charset=GB2312";
	    String headImg_name=(String)request.getSession().getAttribute("headImg_name");
	    String defImg=request.getSession().getServletContext().getRealPath("")+"css\\personalcenter\\profile.png";
	    String iname=headImg_name;
	    
	    String filePath = defImg;
	    if(!StringUtil.isEmpty(iname))
	    {
		    // 本地文件路径
	    	filePath = UploadUtil.img_head+"\\"+iname;
	    }
	    if(!UploadUtil.isFind(filePath))
	    {
	    	   filePath = defImg;
	    }
	    File file = new File(filePath);
        // 获取输出流
        OutputStream outputStream = response.getOutputStream();
        FileInputStream fileInputStream = new FileInputStream(file);
        // 读数据
        byte[] data = new byte[fileInputStream.available()];
        fileInputStream.read(data);
        fileInputStream.close();
        // 回写
        response.setContentType(JPG);
        outputStream.write(data);
        outputStream.flush();
        outputStream.close();
	

	}
	



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值