zoukankan      html  css  js  c++  java
  • FileReader在ios上面的坑(图片转base64)

    https://www.cnblogs.com/samsimi/p/6559591.html

    var fileUpload = function(obj, callback){
    
                //检测浏览器是否支持FileReader对象
                if(typeof FileReader == "undefined"){
                    alert("您的浏览器不支持FileReader对象!");
                }
                var file = obj;
                //判断类型是不是图片
                if(!/image/w+/.test(file.type)){
                    alert("请确保文件为图像类型");
                    return false;
                }
                var reader = new FileReader();
                reader.onload = function (e) {
                    var img = new Image,
                        width = 95,    //图片resize宽度
                        quality = 0.2,  //图像质量
                        canvas = document.createElement('canvas'),
                        drawer = canvas.getContext("2d");
                    img.src = this.result;
                    var scale = parseInt(img.height / img.width);
                    img.width=width;
                    img.height = width * scale;
                    canvas.width = img.width;
                    canvas.height = img.height;
                    drawer.drawImage(testimgId, 0, 0, canvas.width, canvas.height);
                    var base64 = canvas.toDataURL('image/jpeg', 0.2);
                    console.log(base64);
                    var image_base64 = img.src.replace("data:image/png;base64,","");
                    image_base64=encodeURIComponent(image_base64);
                    alert("19")
                    // 调用回调
                    callback&&callback(img.src);
                }
                reader.readAsDataURL(file);
    
            }
  • 相关阅读:
    CSS选择器
    CSS样式与语法
    实训第二天
    初学前端
    html-路径和图像标签
    html
    JavaScript(基础)
    CSS(2)
    CSS()
    HTML(链接与表单)
  • 原文地址:https://www.cnblogs.com/beimingbingpo/p/9753028.html
Copyright © 2011-2022 走看看