小程序自定义相机,canvas实现图片裁剪功能

最近在写小程序项目,需要将拍摄的照片裁剪,去掉多余的部分。

说说本人遇到的bug,一开始在编辑器上测试,没有问题,后面真机调试或预览模式,裁剪的照片坐标都有问题,找了很久才发现是像素的原因,所以在写的时候,一定要特别注意“设备像素比”

重点一定要计算像素比,不然会得不到想要的效果.

该项目主要用于实现下图功能

wxml代码

<cover-view class="lary-top" style="height:{
  {info.statusBarHeight}}px;"></cover-view>
<camera class="camera-photo" frame-size="small" device-position="{
  {devBack}}" flash="off" binderror="error" style="width:{
  {info.windowWidth}}px;height:{
  {info.windowHeight}}px;top:{
  {info.statusBarHeight}}px">
	<cover-view class="page-flex" style="width:{
  {info.windowWidth}}px; height:{
  {info.windowHeight}}px;">
		<cover-view style="height:{
  {info.windowHeight}}px;" class="page-mask page-mask-lr"></cover-view>
		<cover-view class="page-content" style="height:{
  {info.windowHeight}}px;">
			<cover-view class="page-mask" style="height:{
  {convasY-40}}px;"></cover-view>
			<cover-view style="width:{
  {canvasWidth}}px; height:{
  {canvasHeight}}px;margin:auto"></cover-view>
			<cover-view class="page-mask tackPhoto" style="height:{
  {convasY+40}}px">
                <cover-view class="confirm-photo" bindtap="takePhoto">确定</cove
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值