2***@qq.com
2***@qq.com
  • 发布:2019-09-24 16:11
  • 更新:2020-02-07 01:21
  • 阅读:3200

ios设置WKWebview核心之后,html2canvas画不出海报了

分类:HBuilderX

ios设置WKWebview核心之后,html2canvas画不出海报了
安卓系统完好
功能:使用 html2canvas.js 画出一张图片,分享
问题描述
1.设置成UIWebview可以画海报,但是分享成功回到app后失去响应,然后崩溃;

  1. 设置成WKWebview 这个html2canvas 失效,分享功能可用;
    3.组合起来是,这两个核心都是能走通其中一个,整一个功能却无法实现;
    跪求大神--修复bug
    代码
    let _this = this;  
      var canvas2 = document.createElement("canvas");  
      let _canvas;  
      if (ide == 1) {  
        _canvas = "#posterHtml1";  
      } else if (ide == 2) {  
        _canvas = "#posterHtml2";  
      } else if (ide == 3) {  
        _canvas = "#posterHtml3";  
      }  
      // var w = parseInt(window.getComputedStyle(_canvas).width);  
      // var h = parseInt(window.getComputedStyle(_canvas).height);  
      const w = $(_canvas).outerWidth(),  
        h = $(_canvas).outerHeight();  
      let scale = 2;  
      //将canvas画布放大若干倍,然后盛放在较小的容器内,就显得不模糊了  
      canvas2.width = w * scale;  
      canvas2.height = h * scale;  
      canvas2.style.width = w + "px";  
      canvas2.style.height = h + "px";  
      //可以按照自己的需求,对context的参数修改,translate指的是偏移量  
      var context = canvas2.getContext("2d");  
      context.scale(scale, scale);  
      var opts = {  
        scale: scale,  
        width: w,  
        height: h,  
        canvas: canvas2, //自定义 canvas  
        logging: false, //日志开关,便于查看html2canvas的内部执行流程  
        useCORS: true // 【重要】开启跨域配置  
      };  
      html2canvas(document.querySelector(_canvas), opts).then(function(canvas) {  
        // 上传七牛  
        _this.imgmap = canvas.toDataURL();  
        _this.uploadMainImg(_this.dataURLtoBlob(_this.imgmap), ide);  
      });
2019-09-24 16:11 负责人:无 分享
已邀请:
DCloud_UNI_GSQ

DCloud_UNI_GSQ

如果canvas使用网络图像遇到跨域问题,需要服务端设置图像的响应头:Access-Control-Allow-Origin
如果canvas使用本地图像遇到跨域问题,可以使用plus接口将图像转换为base64再使用,相关插件:https://ext.dcloud.net.cn/plugin?id=123

  • 再来买一瓶

    大佬,我是在APP端 执行到canvas.toDataURL('image/png') 这里报跨域错误的,怎么解决呢

    2021-04-08 20:23

NEWcentos

NEWcentos - 90后苦逼前端

你解决了嘛?

chinahappybeer

chinahappybeer - china happy beer

你解决了嘛?

  • 2***@qq.com (作者)

    2020-02-10 09:16

  • 2***@qq.com (作者)

    这个功能我们在ios弹出使用手机截操作了

    2020-02-10 09:17

该问题目前已经被锁定, 无法添加新回复