用java教你学会截图

首先这个问题也困扰了我挺久,慢慢的我就摸索出一条路子,其实也挺简单的。

废话不多说,看我如何降服这妖怪...

首先用到jquery的一个插件,Jcrop。用这个工具截取你需要的图片大小。

然后要提交这个被截图的大小,也就是坐标了。

比如这样的代码: <form  action="/browsing/privacy.do?method=dos" method="post" name="formsa">
                        <input type="hidden" size="4" id="x" name="x" />
                        <input type="hidden" size="4" id="y" name="y" />
                        <input type="hidden" size="4" id="w" name="w" />
                        <input type="hidden" size="4" id="h" name="h" />
                    </form>

这里是记录了4个坐标,截取图片高,宽,和XY的坐标数据。如果为了美观用的不是input文件域按钮的而是用图片的话,这里有一个难点。那怎么解决呢。解决方案就是通过<A hidefocus="true"  class="addfileA" href="javascript:void(0)">
                          <input hidefocus="true"  class="addfileI"  type="file" id="files" name="file" size="1"  οnchange="formsubmit()" /></A>

 

然后定义样式.addfileA{ position:relative; cursor:hand; text-decoration:none; background-image: url('/browsing/pic/sctx02.gif'); width:20px;height: 30px }
.addfileI { cursor:hand; position:relative; left:0px; width:108px;height: 30; background-color: blue; opacity:0; filter:alpha(opacity=0) ;height: 30px}

通过这种方法可以实现图片提交文件域了。(为什么要这样呢,因为为了安全起见规定是不能用JavaScript提交文件域的)

 

图片截取了,坐标搞定了。现在就差如何用java代码截取图片了。

看下面代码:String x = request.getParameter("x");
    String y = request.getParameter("y");
    String w = request.getParameter("w");
    String h = request.getParameter("h");
    String images = request.getParameter("imagesLOAD");
   
    
    ActionForward forwrad = new ActionForward();
 
        User user=((User)request.getSession().getAttribute("user"));
        BrowsingUser browsingUser=browsingUserDAO.load(user.getDataId());
        SystemParameter systemParameter = (SystemParameter) request.getSession().getServletContext().getAttribute("systemParameter");
    String imagesURL=systemParameter.getFileUrlName()+File.separator+images;
    images=images.replace("/", File.separator);
        OperateImage image = new OperateImage(Integer.parseInt(x),Integer.parseInt(y),Integer.parseInt(w),Integer.parseInt(h));
   image.setSrcpath(systemParameter.getFliePath()+File.separator+"touxiang"+File.separator+user.getUsername()+File.separator+images);
        image.setSrcpath(systemParameter.getFliePath()+images);
       
        images=this.returnstring(systemParameter.getFliePath()+images);
     
        image.setSubpath(images);
        image.cut();

 

那么该image就是截取后他图片了路径就是images了。

然后在你要显示截取后图片的地方用images的路径就OK了。

 

欢迎不懂的TZ咨询

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值