MUI上传头像

阅读: 评论:0

MUI上传头像

MUI上传头像

//上传头像练习 -- trueimg 为图片id ElementById("trueimg").addEventListener('tap',function(){ if(mui.os.plus){ var a=[{ title:"拍照" },{ title:"从手机相册选择" }]; plus.nativeUI.actionSheet({ title:"修改用户头像", cancel:"取消", buttons:a },function(b){ switch(b.index){ case 0: break; case 1: //alert("拍照"); getImage();//拍照 break; case 2: //alert("打开相册"); galleryImg();//打开相册 break; default: break; } }); } },false); //拍照 function getImage(){ var c = Camera(); c.captureImage(function(e){ solveLocalFileSystemURL(e,function(entry){ var s = LocalURL() + "?version=" + new Date().getTime(); uploadHead(s);//上传图片 },function(e){ console.log("读取拍照文件错误:"&#ssage); }); },function(s){ console.log("error"+s); },{ filename:"_doc/bg.png" }) } //从相册选图上传 function galleryImg(){ plus.gallery.pick(function(a){ solveLocalFileSystemURL(a,function(entry){ solveLocalFileSystemURL("_doc/",function(root){ File("bg.png",{},function(file){ //文件已存在 ve(function(){ console.log("file remove success"); pyTo(root,'bg.png',function(e){ var e=e.fullPath+"?version="+new Date().getTime(); uploadHead(e);//上传图片 }, function(e){ console.log('copy image file:'&#ssage); }); },function(){ console.log('delete image file:'&#ssage); }); },function(){ //文件不存在 pyTo(root,'bg.png',function(e){ var path = e.fullPath +"?version="+new Date().getTime(); uploadHead(path); },function(e){ console.log('copy image fail:'&#ssage); }); }); },function(e){ console.log("get _www folder fail"); }) },function(e){ console.log("读取拍照文件错误:"&#ssage); }); },function(a) {},{ filter:"image" }) }; //上传头像图片 function uploadHead(imgPath){ console.log("imgPath ="+imgPath); var mainImage = ElementById("trueimg"); mainImage.src = imgPath; mainImage.style.width = "64px"; mainImage.style.height = "64px"; var image = new Image(); image.src = imgPath; load = function(){ var imgData = getBase64Image(image); } } //将图片压缩成base64 function getBase64Image(img){ var canvas = ateElement("canvas"); var width = img.width; var height = img.height; if(width>height){ if(width>100){ height = und(height *= 100/width); width = 100; } }else{ if(height>100){ width = und(width *= 100/height); height = 100; } } canvas.width = width; canvas.height = height; var ctx = Context("2d"); ctx.drawImage(img,0,0,width,height); var dataURL = DataURL("image/png",0.8); place("data:image/png;base64,",""); }

参考网址:.html


本文发布于:2024-01-27 18:37:50,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/17063518701934.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

上一篇:调取相机
下一篇:H5
标签:头像   上传   MUI
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23