熊海
熊海
  • 发布:2019-09-24 18:06
  • 更新:2019-09-24 18:12
  • 阅读:924

【报Bug】nvue下plus.zip.compressImage 无法改变图片大小和旋转角度那些

分类:nvue

详细问题描述

(DCloud产品不会有明显的bug,所以你遇到的问题大都是在特定环境下才能重现的问题,请仔细描述你的环境和重现方式,否则DCloud很难排查解决你的问题)

[内容]

var t=new Date();
let tempfile="tempxingxiang"+t.getTime()+".png";
plus.zip.compressImage({
src:path,
dst:"_doc/"+tempfile,
overwrite:true,
format:"png",
width:realwidth+"px",
height:realheight+"px",
quality:80,
},function(res){
console.log("压缩成功"+JSON.stringify(res));
that.chooseimage=res.target;
uni.getImageInfo({
src:that.chooseimage,
success:function(data){
console.log("压缩后文件"+JSON.stringify(data));
}});
that.avatarstyle="width:"+realwidth+"px;height:"+realheight+"px";
console.log(that.avatarstyle);
});

最后res返回的数据,图片大小,还是原来的大小。

重现步骤

[步骤]

[结果]

[期望]

[如果语言难以表述清晰,拍一个视频或截图,有图有真相]

IDE运行环境说明

[HBuilder 或 HBuilderX。如果你用其他工具开发uni-app,也需要在此说明]

[IDE版本号]

[windows版本号]

[mac版本号]

uni-app运行环境说明

[运行端是h5或app或某个小程序?]

[运行端版本号]

[项目是cli创建的还是HBuilderX创建的?如果是cli创建的,请更新到最新版cli再试]

[编译模式是老模板模式还是新的自定义组件模式?]

App运行环境说明

[Android版本号]

[iOS版本号]

[手机型号]

[模拟器型号]

附件

[IDE问题请提供HBuilderX运行日志。菜单帮助-查看运行日志,点右键打开文件所在目录,将log文件压缩成zip包上传]

[App问题请提供可重现问题的代码片段,你补充的细一点,问题就解决的快一点]

[App安装包或H5地址]

[可重现代码片段]

联系方式

[QQ]

2019-09-24 18:06 负责人:无 分享
已邀请:
熊海

熊海 (作者)

完整的代码:

var that = this;

            plus.gallery.pick(function(path) {  
                console.log(path);  

                uni.getImageInfo({  
                    src:path,  
                    success(data) {  
                        console.log(JSON.stringify(data));  
                        let widthrate=data.width/114;  
                        let heightrate=data.height/264;  
                        let realwidth;  
                        let realheight;  
                        if(widthrate>heightrate) //如果宽度缩放比例大,那么代表垂直会变成居中了。  
                        {  
                            realwidth=data.width/widthrate;  
                            realheight=data.height/widthrate;  
                        }  
                        else{  
                            realwidth=data.width/heightrate;  
                            realheight=data.height/heightrate;  
                        }  
                        console.log(realwidth+":"+realheight);  
                        var t=new Date();  
                        let tempfile="tempxingxiang"+t.getTime()+".png";  
                        plus.zip.compressImage({  
                            src:path,  
                            dst:"_doc/"+tempfile,  
                            overwrite:true,  
                            format:"png",  
                            width:realwidth+"px",  
                            height:realheight+"px",  
                            quality:80,  
                        },function(res){  
                            console.log("压缩成功"+JSON.stringify(res));  
                            that.chooseimage=res.target;  
                            uni.getImageInfo({  
                                src:that.chooseimage,  
                                success:function(data){  
                                    console.log("压缩后文件"+JSON.stringify(data));  
                                }});  
                            that.avatarstyle="width:"+realwidth+"px;height:"+realheight+"px";  
                            console.log(that.avatarstyle);  
                        });  
                    }  
                })  

            }, function(e) {  
                console.log("取消选择图片");  
            }, {  
                filter: "image"  
            });
DCloud_iOS_XHY

DCloud_iOS_XHY

问题确认中

熊海

熊海 (作者)

我之所以要压缩图片。是在ios下,如果不压缩图片的话,图片就无法进行操作。包括上传,绘制到canvas里面。下面是我绘制的代码:

uni.chooseImage({
count: 1,
success(res) {

                    let file = res.tempFilePaths[0];  

                    console.log(file);  
                    var ctx = that.context;  
                    ctx.clearRect(0, 0, 110, 110);  
                    ctx.save();  
                    ctx.beginPath();  
                    ctx.arc(55, 55, 55, 0, 2 * Math.PI);  

                    ctx.clip();  
                    ctx.drawImage(  
                        file,  
                        0, 0, 110, 110);  
                        /*  
                    ctx.setStrokeStyle('#ffffff');  
                    ctx.setLineWidth(2);  
                    ctx.stroke();  
                    */  
                    ctx.closePath();  
                    ctx.restore();  
                    ctx.draw(true);  
                    choosedimage = true;  
                }  
            })  

如果选择的图片是大的,感觉是1M。就会drawimage没有任何效果。选择小的,就可以。所以,我需要图片压缩。

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