|
- //图片缓存到本地
- function cacheImage(imagepath,filepath,filename,callback,isShowLoading){
- if(!arguments[0]) return;
- if(!arguments[4]) isShowLoading = false;
- var savePath = 'fs://'+filepath+'/original/'+filename+'.jpeg';
- //判断地址是否为远程地址 http 或 https
- if(getUrl(imagepath)){
- if(isShowLoading){
- api.showProgress();
- }
- api.download({
- url: imagepath,
- savePath: savePath,
- report: true,
- cache: true,
- allowResume: true
- }, function (ret, err) {
- if(ret.state === 1){
- if(isShowLoading){
- api.hideProgress();
- }
- compressLocalImage(savePath,filepath,filename,callback);
- }else if(ret.state === 2){
- if(isShowLoading){
- api.hideProgress();
- }
- }
- });
- }else{
- compressLocalImage(imagepath,filepath,filename,callback);
- }
- }
- function compressLocalImage(imagepath,filepath,filename,callback){
- if(!arguments[0]) return;
- var imgPath = 'fs://'+filepath+'/thumb';
- var compress_savePath = imgPath+"/"+filename+".jpeg";
- var imageFilter = api.require('imageFilter');
- **.**press({
- img: imagepath,
- quality: 0.3,
- save: {
- imgPath: imgPath,
- imgName: filename+".jpeg"
- }
- },function( ret, err ){
- if( ret.status ){
- //删除缓存文件夹
- var fs = api.require('fs');
- fs.rmdir({path: 'fs://'+filepath+'/original'}, function(ret, err) {});
- var data = {
- state:1,
- savePath:compress_savePath,
- };
- callback(data);
- }
- });
- }
- //QQ分享
- var QQPlus = null;
- function shareQQImage(type,imagepath,filepath,filename){
- if(!arguments[0]) type = "QFriend";
- if(!QQPlus){
- QQPlus = api.require('QQPlus');
- QQPlus.setIsPermissionGranted({granted:true});
- }
- QQPlus.installed(function(ret, err) {
- if (ret.status) {
- cacheImage(imagepath,filepath,filename,function (ret,err) {
- if(ret.state === 1){
- var savePath = ret.savePath;
- QQPlus.shareImage({
- type : type,
- imgPath: savePath
- },function(ret,err){
- });
- }
- },true);
- } else {
- showMessage("请先安装QQ~_~!");
- }
- });
- }
复制代码 |
|