uni.chooseImage 的用法

// 拍照
camera(){
let that = this;
uni.chooseImage({
count: 1, //默认9
sizeType: [‘compressed’], //可以指定是原图还是压缩图,默认二者都有
sourceType: [‘camera’,‘album’], //从相册选择
success: function (res) {
console.log(‘img’,res)
imgToBase64(res)
}
})

// 图片转base64
function imgToBase64(data){
	 plus.zip.compressImage({  
		src: data.tempFilePaths[0],  
		dst: "_doc/a.jpg",  
		overwrite: true,  
		width: '1920px',  
		height:'1080px',  
		format: 'jpg',  
		quality: 100  
	  },  
	  function(e) {  
		let reader = new plus.io.FileReader();  
			reader.readAsDataURL(e.target);  
			reader.onloadend = function (e) { 
				//这是转成功的base64文件,需要正则去一下换行
				let base64 = e.target.result.split(',')[1].replace(/[\r\n]/g,"") 
				iOCR(base64)
			};  
	  },  
	  function(err) {  
		plus.nativeUI.alert('未知错误!',function() {  
		});  
	  }  
	);  
}

// iOCR文字识别
function iOCR(image){
	uni.request({
		url:`https://aip.baidubce.com/rest/2.0/solution/v1/iocr/recognise/finance?access_token=${that.access_token}`,
		header:{
			'Content-Type':'application/x-www-form-urlencoded'
		},
		method:"POST",
		data:{
			image:image,
			// 模版id
			templateSign:that.templateSign,
		},
		success:(res)=>{
			console.log('识别结果',res)
		},
		fail:(err)=>{
			console.log('err',err)
		}
	})
}

},

原文链接:https://blog.csdn.net/weixin_35958891/article/details/108284292

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值