当前位置: 首页 > news >正文

uniapp-微信小程序调用摄像头

 1.uniapp中的index.vue代码

<template><view class="content"><view class="container"><!-- 摄像头组件 --><camera id="camera" device-position="front" flash="off" binderror="onCameraError">333</camera><!-- 拍照按钮 --><button @click="takePhoto">拍照</button><!-- 显示拍照结果 --><image v-if="photo" :src="photo" mode="aspectFit"></image></view></view>
</template><script setup>
import {ref} from 'vue'
import demo1Vue from '../demo1/demo1.vue';const photo = ref('')const takePhoto = () => {const cameraContext = uni.createCameraContext(this);  // 创建摄像头上下文cameraContext.takePhoto({quality: 'high',  // 照片质量:high, medium, lowsuccess: (res) => {photo.value = res.tempImagePath;  // 获取拍照后的图片路径console.log(photo.value)},fail: (err) => {console.log('拍照失败', err);}});}// 摄像头错误回调const onCameraError = (e) => {console.log('摄像头发生错误', e.detail);}
</script><style></style>

2.manifest.json

声明配置权限

"mp-weixin" : {"appid" : "wx8********91","setting" : {"urlCheck" : false},"usingComponents" : true,"permission": {"scope.camera": {"desc": "需要获取摄像头权限进行拍照"}}},

3.微信小程序必须真机测试摄像头 

http://www.lryc.cn/news/506201.html

相关文章:

  • 鸿蒙学习笔记:用户登录界面
  • 无人机航测系统技术特点!
  • 《算法ZUC》题目
  • 配置flutter 解决andriod studio报错 no device selected
  • docker搭建Redis集群及哨兵(windows10环境,OSS Cluster)
  • 信息化基础知识——数字政府(山东省大数据职称考试)
  • 信息安全实训室网络攻防靶场实战核心平台解决方案
  • Nginx主要知识点总结
  • PySide6程序框架设计
  • 「九」HarmonyOS 5 端云一体化实战项目——「M.U.」应用云侧开发云数据库
  • 记录:virt-manager配置Ubuntu arm虚拟机
  • clickhouse-介绍、安装、数据类型、sql
  • 【shell】常用100个shell命令使用讲解
  • Git-分支(branch)常用命令
  • 谈谈es6 Map 函数
  • 微信小程序:实现节点进度条的效果;正在完成的节点有动态循环效果;横向,纵向排列
  • 【Unity3D】无限循环列表(扩展版)
  • MacOS 命令行详解使用教程
  • redis集群安装部署 redis三主三从集群
  • 第十二课 Unity 内存优化_内存工具篇(Memory)详解
  • 达梦8-达梦数据的示例用户和表
  • 数据可视化-1. 折线图
  • 【现代服务端架构】传统服务器 对比 Serverless
  • 论文学习—VAE
  • AI 智能体(AI Agent)到底什么原理?能干什么事情
  • 【mysql】如何查看大表记录行数
  • Linux之网络配置
  • SpringBoot集成JWT和Redis实现鉴权登录功能
  • LabVIEW热电偶传感器虚拟仿真实验系统
  • Centos7 部署ZLMediakit