l***@163.com
l***@163.com
  • 发布:2019-10-29 15:40
  • 更新:2019-11-19 22:14
  • 阅读:3160

通过uni.chooseImage() 选择图片后,怎么获得图片的base64编码数据?

分类:HTML5+

通过uni.chooseImage() 选择图片都,怎么获得图片的base64编码数据?

2019-10-29 15:40 负责人:无 分享
已邀请:
8***@qq.com

8***@qq.com - 自由工作比上班赚的多

看这里 http://hhyang.cn/doc4/

2***@qq.com

2***@qq.com

uni.chooseImage({  
        sizeType: ['original'],  
        sourceType: ['camera'],  
        success: function (res) {  
            console.log(JSON.stringify(res.tempFilePaths));  
            var allFiles = res.tempFilePaths;  
            var tmpimg = allFiles[0];  
            console.log(tmpimg)  
            //#ifdef APP-PLUS  
            plus.io.resolveLocalFileSystemURL(tmpimg, function(entry){  
                entry.file(function(file){    
                    var reader = new plus.io.FileReader();    
                    reader.onloadend = function (e) {  
                        var base64=e.target.result  
                        console.log(base64);  
                        var name=tmpimg.substring(tmpimg.lastIndexOf('/') + 1);  
                        var img={path:tmpimg,name:name,src:base64};  
                        var EXIF=require('@/common/js/js_sdk/exif/exif.js');  
                        EXIF.getData(img, function(){  
                            console.log(EXIF.pretty(this));  
                            console.log('AllTags:',EXIF.getAllTags(this)) // 此处打印的为选中图片的数据  
                            console.log(EXIF.getTag(this, 'Orientation'));  
                          var tagj=EXIF.getTag(this,'GPSLongitude');  
                          var tagw=EXIF.getTag(this,'GPSLatitude');  
                          if(tagj&&tagw) {  
                              var longitude=tagj[0]+tagj[1]/60+tagj[2]/60/60;  
                              var latitude=tagw[0]+tagw[1]/60+tagw[2]/60/60;  
                              var lalinfo=this.name+":"+longitude+":"+latitude+",";  
                              console.log(lalinfo);  
                              uni.openLocation({latitude:latitude,longitude:longitude});  
                          }  
                        })  
                    };    
                    reader.readAsDataURL(file);    
                },function(e){    
                    console.log("读写出现异常: " + e.message );  
                    throw "Could not load image";  
                })    
            })   
            //#endif  
        }

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