vue转移动端调取摄像头方法汇总

一. input

这种方式是文件录入的方式需要做二次操作,相当于上传文件,所以界面可能会有很多选择方式,摄像头不是唯一,如果我们想直接点击调取摄像头这种方式行不通

<input type="file" accept="video/*"/> // 摄像
<input type="file" accept="image/*"/> // 图片
<input type="file" accept="radio/*"/> // 音频

在这里插入图片描述

二. HTML5(Camera)

Camera模块管理设备的摄像头,可用于拍照、摄像操作,通过plus.camera获取摄像头管理对象。
这个方式可以点击直接调取摄像头
1.index.html

	document.addEventListener( "plusready", onPlusReady, false );
	function onPlusReady() {
		console.log("plusready");
	}

2.在调取的页面:

<template>
	<div class="home">
		<div class="page-header">
			拍摄
		</div>
		<div class="content">
			<button @click="captureImage">摄像</button>
		</div>
	</div>
</template>
<script>
	export default {
		name: 'home',
		data() {
			return {
			}
		},
		components: {
		},
		created() { 
		},
		mounted() {
		},
		methods: {
			captureImage(){
				var cmr = plus.camera.getCamera();
				var res = cmr.supportedImageResolutions[0];
				var fmt = cmr.supportedImageFormats[0];
				console.log("Resolution: "+res+", Format: "+fmt);
				// 摄像
				// cmr.startVideoCapture( function( path ){
				// 		alert( "Capture video success: " + path );  
				// 	},
				// 	function( error ) {
				// 		alert( "Capture video failed: " + error.message );
				// 	},
				// 	{resolution:res,format:fmt}
				// );
				// 拍照
				cmr.captureImage( function( path ){
					alert( "Capture image success: " + path );
				},
				function( error ) {
					alert( "Capture image failed: " + error.message );
					},
					{resolution:res,format:fmt}
				);
			},
		}
	}
</script>
  • 0
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值