赞
踩
1.获取图片的原始宽高,并获取到图片原始宽高的宽高比
- let src = "图片地址"
- wx.getImageInfo({
- src,
- success: function(res){
- let originalWidth = res.width;
- let originalHeight = res.height;
- let originalScale = parseInt(originalHeight/originalWidth);//图片高宽比
- }
- })
2.获取屏幕的宽高,并获取到屏幕宽高的宽高比
-
- wx.getSystemInfo({
- success: function (res) {
- let windowWidth = res.windowWidth - 36 ;
- let windowHeight = res.windowHeight;
- let windowscale = parseInt(windowHeight/windowWidth);//屏幕高宽比
- }
- })
3.计算图片尺寸
- if(originalScale < windowscale){//图片高宽比小于屏幕高宽比
- //图片缩放后的宽为屏幕宽
- imageSize.imageWidth = parseInt(windowWidth);
- imageSize.imageHeight = parseInt((windowWidth * originalHeight) / o
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。