java海报拼接上小程序二维码

需求是公司要给后台发布的海报,每个人看到的时候吧自己的小程序二维码拼接上去

上代码

 

获取小程序二维码

String url="https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=ACCESS_TOKEN";
                    Map<String,Object> param=new HashMap<String, Object>();
                    if(sysEmployee==null){
                        param.put("scene","0");
                    }else{

                 带上自己的参数
                        param.put("scene",""+sysEmployee.getEmployeeId());
                    }
                    param.put("page","pages/home/home");
                    param.put("width","350px");
                    //param.put("auto_color","false");
                    //param.put("lineColor","{"r":0,"g":0,"b":0}");
                    //param.put("is_hyaline",true);是否透明,建议还是白底,不然拼接上很有可能识别不了
                    url=url.replace("ACCESS_TOKEN", accessToken);     
                    byte[] result =HttpUtil.postReturnBytes(url, null, JSONObject.toJSONString(param),null);
                    return result;

java代码拼接图片

response.setContentType("text/html; charset=UTF-8");//设置返回数据的格式
            response.setContentType("image/jpeg");
            //获取图片的url
            OutputStream os = response.getOutputStream();
            try {
                byte[] bigByte= bigByte;
                byte[] smallByte=smallByte;
                ByteArrayInputStream bigIn = new ByteArrayInputStream(bigByte);    //将大图片作为输入流;
                ByteArrayInputStream smallIn = new ByteArrayInputStream(smallByte);    //将二维码作为输入流;
                BufferedImage big = ImageIO.read(bigIn); 
                BufferedImage small =  ImageIO.read(smallIn);
                //不重新绘制,会报invalid argument to native writeimage,重新绘制后就可以了

                BufferedImage tag;
                tag = new BufferedImage(big.getWidth(), big.getHeight(), BufferedImage.TYPE_INT_BGR);
                Graphics gg = tag.getGraphics();
                gg.drawImage(big, 0, 0, null); // 绘制缩小后的图
                gg.dispose();
                big = tag;
                
                //开始拼接图片
                Graphics g = big.getGraphics();
                int x = big.getWidth()-big.getWidth()*postersAndShareImg.getPasiShareX()/100;
                int y = big.getHeight()-big.getHeight()*postersAndShareImg.getPasiShareY()/100;
                g.drawImage(small, x, y, 50, 50, null);
                g.dispose();
                ImageIO.write(big, "jpeg", os);
            } catch (Exception e) {
                e.printStackTrace();
            }

小程序端的点击图片,预览功能,可以长按发送给朋友或者保存到相册

previewImageAction:function(e){

    var url=e.currentTarget.dataset.url;

    wx.previewImage({

      urls: [url],

      complete: (res) => {},

      current: 'current',

      fail: (res) => {},

      success: (res) => {},

    })

  }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值