zoukankan      html  css  js  c++  java
  • js 图片保存至手机相册

    1.网络地址进行保存

    var triggerEvent = "touchstart";  //指定下载方式
        function savePicture(Url) {
            var blob = new Blob([''], { type: 'application/octet-stream' });
            var url = URL.createObjectURL(blob);
            var a = document.createElement('a');
            a.href = Url;
            a.download = Url.replace(/(.*/)*([^.]+.*)/ig, "$2").split("?")[0];
            var e = document.createEvent('MouseEvents');
            e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
            a.dispatchEvent(e);
            URL.revokeObjectURL(url);
        }
    savePicture(Url); 
    // Url 为图片的服务器地址  http://****.com/cwap/images/userqrcode/06144477550415791.pngfinal.png

    2.临时地址也可以保存: blob:http://localhost:8080/d08f95f2-06da-4f9c-864e-c00079fc1c6f
    var file = files[0];//上传控件选择的文件对象
    var url = window.URL.createObjectURL(file);//用此方法有兼容问题
    savePicture(Url); 
    
    
    //下面是兼容方法
    
    //获取图片路径
    function getObjectURL (file){
      let url = null ;
      if (window.createObjectURL!=undefined) { // basic
        url = window.createObjectURL(file) ;
      } else if (window.URL!=undefined) { // mozilla(firefox)
        url = window.URL.createObjectURL(file) ;
      } else if (window.webkitURL!=undefined) { // webkit or chrome
        url = window.webkitURL.createObjectURL(file) ;
      }
      return url ;
    }

    转: https://blog.csdn.net/weixin_43271750/article/details/97639465

  • 相关阅读:
    列表
    Pyunit测试框架
    Jmeter性能测试入门(转)
    Monkey for iOS(CrashMonkey4IOS)
    美化iTerm2
    不经过 App store 的安装方式(转)
    Mac上部署JDK/Ant/Jmeter/Jenkins
    display:inline-block元素之间错位问题
    vue项目安装依赖报错没有python
    正则匹配所有li标签内容
  • 原文地址:https://www.cnblogs.com/fps2tao/p/12941066.html
Copyright © 2011-2022 走看看