• h5 拍照上传 代码


    1. 定义表单

    <input id="upload" type="file" accept="image *;" capture="camera"  =""></input id="upload" type="file" accept="image>

    2.调用图像流

    var demo_h5_upload_ops = {
        init:function(){
            this.eventBind();
        },
        eventBind:function(){
            var that = this;
            $("#upload").change(function(){
                var reader = new FileReader();
                reader.onload = function (e) {
                    that.compress(this.result);
                };
                reader.readAsDataURL(this.files[0]);
            });
        },
        compress : function (res) {
            var that = this;
            var img = new Image(),
                maxH = 300;
     
            img.onload = function () {
                var cvs = document.createElement('canvas'),
                    ctx = cvs.getContext('2d');
     
                if(img.height > maxH) {
                    img.width *= maxH / img.height;
                    img.height = maxH;
                }
                cvs.width = img.width;
                cvs.height = img.height;
     
                ctx.clearRect(0, 0, cvs.width, cvs.height);
                ctx.drawImage(img, 0, 0, img.width, img.height);
                var dataUrl = cvs.toDataURL('image/jpeg', 1);
                $(".img_wrap").attr("src",dataUrl);
                $(".img_wrap").show();
                // 上传略
                that.upload( dataUrl );
            };
     
            img.src = res;
        },
        upload:function( image_data ){
            /*这里写上传方法,图片流是base64_encode的*/
        }
    };
     
     
    $(document).ready( function(){
        demo_h5_upload_ops.init();
    } );
    

      

  • 相关阅读:
    mysql
    Spring MVC
    springSecurity
    导出Excel报表
    Redis集群搭建
    Oracle 分析数据库表行长度的统计信息 使用聚簇的步骤
    Dbms.job 学习
    oracel 学习系列
    Oracle 工具类 Sql 分析索引的 碎片率
    oracl
  • 原文地址:https://www.cnblogs.com/vali/p/6482947.html
Copyright © 2020-2023  润新知