本文介绍了微信小程序图片选择区域屏裁剪实现方法,分享给大家。具体如下:
效果图
CSS代码
border-bottom: 2rpx #f98700 solid;
padding-bottom: 20rpx;
}
.cutImg_Box .cutImg_Boxt{
width: 90%;
margin: 20rpx auto;
}
.cutImgBox image{
width: 100%;
}
.cutImg_Box .cutImg_Box_b{
margin-top: 20rpx;
width: 80%;
height: 80rpx;
line-height: 80rpx;
background: #f98700;
color: #fff;
border-radius: 10rpx;
text-align: center;
margin:0rpx auto;
}
.selectCutMode{
background: #fff;
display: flex;
justify-content: space-between;
align-items: center;
}
.selectCutMode .selectCutMode_in{
width: 100%;
text-align: center;
background: #fff;
color: #f98700;
font-size: 24rpx;
padding: 20rpx;
}
.selectCutMode .selectCutMode_inact{
background: #f98700;
color: #fff;
padding: 20rpx;
}
.areaSelctBox{
width: 100%;
display: flex;
align-items: center;
height: 50rpx;
justify-content: center;
margin-top: 20rpx;
}
.areaSelct_Box slider{
width: 80%;
}
.cutImg_Box .clickCutImg_txt{
width: 100%;
text-align: center;
height: 50rpx;
font-size: 24rpx;
line-height: 50rpx;
color: #999;
}
JS代码部分
初始加载带入上一个页面带过来的参数路径
//获取当前屏幕宽度 var phoneW = Number(util.nowPhoneWH()[0]*90)/100; var cutH = 150; wx.getImageInfo({ src: aa,success: function (res) { var w = phoneW; var h = (phoneW/Number(res.width))*Number(res.height) ctx.save() ctx.drawImage(aa,w,h) ctx.restore() ctx.setFillStyle('red') ctx.fillRect(0,phoneW,cutH) ctx.draw() that.setData({ canvasW:w,canvasH:h,img:aa,cutH:cutH }) } }) },