小程序下载canvas生成图片

摘要:
~',}); 那个setData;},失败:函数{console.log;console.log;wx.showToast({title:'保存图片失败!
  save_share_img:function(img){

      var that = this;
      let { result } = that.data;

      getData.getData(
          "save_share_img",
          {
              id                : result.id,
              share_img_link    : img,
              method            : "POST"
          },
          function(data) {
              if (data.errno){
                  console.log(data.errdesc);
                  return;
              }

              result.share_img = img;
              that.setData({
                  result: result
              });

          }
      );
  },
  download:function(){
      var that = this;
      let { urls,result } = that.data;

      console.log(result);
      if (result.share_img == ''){

          // 临时图片上传cdn
          wx.uploadFile({            // 需要传到cdn 才可以下载!!!!!
              url       : "https://a.xxxxx.com/xxxxx/Public/upload_more_img",
              filePath  : urls,
              name      : "file",
              success   : res => {
              },
              fail : res => {
              },
              complete: res => {
                var imgdata = JSON.parse(res.data);
                var img = imgdata.data[0];
                that.save_share_img(img);
                urls = img;
              }
          })
      } else {
          urls = result.share_img;
      }


      console.log('download---start');
      console.log(urls);

      wx.downloadFile({
          url: urls,
          //url:'https://cdn.xxxxxx.net/avatar_3.png',  // canvas 生成的临时图片不可
          success: function(res) {    // 只要服务器有响应数据,就会把响应内容写入文件并进入 success 回调,业务需要自行判断是否下载到了想要的内容
              console.log(res)
              if (res.statusCode == 200) {
                  wx.saveImageToPhotosAlbum({
                      filePath: res.tempFilePath,
                      success: function(res) {
                          console.log(res);
                          console.log('succ');
                          wx.showToast({
                              title: '保存图片成功!~',
                          });

                          that.setData({
                              mask_btn: 0,
                              share_btn: false,
                              canvas_btn:false
                          });
                      },
                      fail: function(res) {
                          console.log(res);
                          console.log('fail');
                          wx.showToast({
                              title: '保存图片失败!~'
                          });
                      },
                      complete:function(res){
                          console.log(res);
                          console.log('complete');
                      }
                  })
              } else {
                  console.log('下载图片发生错误----');
                  wx.showToast({
                      title: '保存图片发生错误!~'
                  });
              }
          },
          fail: function(res){
              console.log('下载图片发生错误');
              console.log(res);

          }
      });

      console.log('download---over');

  },
  previewImg: function() {
    var that = this;

    wx.getSetting({
        success(res) {
            console.log('-------------');
            console.log(res);

            if (!res.authSetting['scope.writePhotosAlbum']) {      // 获取授权!!!!
                wx.authorize({
                    scope:'scope.writePhotosAlbum',
                    success() {
                        that.download();
                        console.log('授权成功')
                    }
                });

            } else {
                that.download();
                console.log('已授权');
            }
        }
    })

免责声明:文章转载自《小程序下载canvas生成图片》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇idea运行main方法或Test避免编译整个应用的方法matlab中类的定义和使用下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

注解@Slf4j

如果不想每次都写private final Logger logger = LoggerFactory.getLogger(XXX.class); 可以用注解@Slf4j 一、在pom文件加入依赖 <dependency><groupId>org.projectlombok</groupId><artifactId...

Apache 分割日志

为什么要分割日志 随着网站的 访问越来越大,WebServer产生的日志文件也会越来越大,如果不对日志进行分割,那么只能一次将大的日志(如Apache的日志)整个删除,这样也 丢失了很多对网站比较宝贵的信息,因为这些日志可以用来进行访问分析、网络安全监察、网络运行状况监控等,因此管理好这些海量的日志对网站的意义是很大 的。 本文将总结一些实用的日志分割方...

Oracle sqlldr命令

今天别人的入库代码,看的真有点晕,最后看完才知道是用了sqlldr命令。哎。。。还是学艺不精啊,今后还是要多努力。 总结哈sqlldr命令:虽然大多是网上来的,自己要有体会嘛 !开源就是好啊。 sqlldr是cmd下的命令,用来将文本格式数据导入到数据库中。 命令格式: sqlldr username/password@sid control=*.ctl...

Draw with a Canvas

When you're writing an application in which you would like to perform specialized drawing and/or control the animation of graphics, you should do so by drawing through a Canvas. A...

关于我的eclipse的老毛病的解决方案

先来一段困扰我多年(长达三个月)的错误报告: 2月 18, 2020 3:43:34 下午 org.apache.catalina.startup.VersionLoggerListener log信息: Server.服务器版本: Apache Tomcat/9.0.272月 18, 2020 3:43:34 下午 org.apache.catalina...

android: 记录app运行过程中产生的log

有时在解决问题时,经常需要借助logcat才能分析定位问题,这里写了一个小工具,能够记录app运行期间的log, 这样测试人员在反馈bug时,只需要把logcat发给我们就可以了。具体代码如下: import android.content.Context; import android.content.Intent; import android.net...