bsf-mask-cameraUnder maintenance

camerauniapputs相机识别

原生相机自定义蒙版的UTS插件

Project Start

2025-02-28

Crowdfunding Success

2024-02-01

Launch

2025-02-28

bsf-mask-camera

bsf-mask-camera 是基于原生相机开发的UTS插件,可自定义蒙版用于人脸识别,身份证拍照等。

平台支持

  • iOS
  • Android
  • 微信小程序
  • uniapp / uniappx

使用示例

<bsf-mask-camera 
  ref="CameraView" 
  @onPermissionDeny="onPermissionDeny"
  @onTakePhoto="onTakePhoto" 
  @onGetFrame="onGetFrame"
  :style="{ height: cameraHeight + 'px', width: cameraWidth + 'px' }"
></bsf-mask-camera>

API 接口

方法

takePicture()

拍照并返回照片数据。

this.$refs.CameraView.takePicture()

startFrame(options)

开启帧监听。

参数

  • options: Object
    • width: Number - 帧宽度
    • height: Number - 帧高度
this.$refs.CameraView.startFrame({
  width: 320,
  height: 640
})

stopFrame()

停止帧监听。

this.$refs.CameraView.stopFrame()

stopCamera()

关闭相机。

this.$refs.CameraView.stopCamera()

switchCamera()

切换前后摄像头。

this.$refs.CameraView.switchCamera()

switchFlash()

切换闪光灯开关。

this.$refs.CameraView.switchFlash()

事件

onPermissionDeny

相机权限被拒绝时触发。

onTakePhoto

拍照完成时触发,返回照片数据。

onGetFrame

获取视频帧时触发,返回帧数据。

示例代码

export default {
  methods: {
    takePhoto() {
      this.$refs.CameraView.takePicture()
    },
    
    onTakePhoto(res) {
      console.log('照片数据:', res)
    },
    
    onPermissionDeny() {
      uni.showToast({
        title: '相机权限被拒绝',
        icon: 'error'
      })
    },
    
    onGetFrame(res) {
      console.log('帧数据:', res) 
    }
  }
}

saveContentToICloud(options)

将内容保存到 iCloud。

参数

  • options: Object
    • fileName: String - 文件名称
    • content: String - 要保存的内容
    • success: Function - 成功回调函数
    • fail: Function - 失败回调函数,参数为错误信息

示例

Icloud.saveContentToICloud({
  fileName: '1.txt',
  content: '要保存的内容',
  success: () => {
    console.log('保存成功');
  },
  fail: (err) => {
    console.error('保存失败:', err);
  }
});