更新记录
1.2.2(2026-01-21)
1.2.1(2026-01-21)
1.1.2(2026-01-21)
查看更多
平台兼容性
uni-app(4.31)
| Vue2 |
Vue3 |
Chrome |
Safari |
app-vue |
app-nvue |
app-nvue插件版本 |
Android |
Android插件版本 |
iOS |
鸿蒙 |
| × |
× |
× |
× |
× |
√ |
1.0.0 |
5.0 |
1.0.0 |
× |
- |
| 微信小程序 |
支付宝小程序 |
抖音小程序 |
百度小程序 |
快手小程序 |
京东小程序 |
鸿蒙元服务 |
QQ小程序 |
飞书小程序 |
小红书小程序 |
快应用-华为 |
快应用-联盟 |
| - |
- |
- |
- |
- |
- |
- |
- |
- |
- |
- |
- |
uni-app x(4.31)
| Chrome |
Safari |
Android |
Android插件版本 |
iOS |
鸿蒙 |
微信小程序 |
| × |
× |
5.0 |
1.0.0 |
× |
× |
- |
其他
biming-camera
一个基于 CameraX 实现的 Android 原生相机组件。
平台支持
- [x] Android
- [x] nvue、uvue
使用方法
NVUE 示例
<template>
<view>
<biming-camera ref="camera" style="width: 100%; height: 300px;"></biming-camera>
<button @click="handleSwitchCamera">切换摄像头</button>
<button @click="handleTakePhoto">拍照</button>
<button @click="handleGetCurrentFrame">获取当前帧</button>
<image v-if="imageData" :src="imageData" style="width: 100px; height: 150px;"></image>
</view>
</template>
<script>
export default {
data() {
return {
imageData: ''
}
},
methods: {
handleSwitchCamera() {
this.$refs.camera.switchCamera();
},
handleTakePhoto() {
this.$refs.camera.captureImage((base64) => {
console.log('照片已拍摄, Base64 长度:', base64.length);
this.imageData = 'data:image/jpeg;base64,' + base64;
});
},
handleGetCurrentFrame() {
this.$refs.camera.getFrameBase64((res, base64) => {
if (res) {
console.log('当前帧已获取, Base64 长度:', base64.length);
this.imageData = 'data:image/jpeg;base64,' + base64;
} else {
console.log('获取失败', base64);
}
});
}
}
}
</script>
UVUE 示例
<template>
<view>
<!-- 放置相机组件 -->
<biming-camera ref="camera" :defaultCamera="currentCamera" style="width: 100%; height: 300px;" @error="onCameraError"></biming-camera>
<!-- 控制按钮 -->
<button @click="switchCm">切换摄像头</button>
<button @click="takePhoto">拍照</button>
<button @click="getFrame">获取预览帧</button>
<!-- 显示拍摄或截取的图片 -->
<image v-if="imgSrc != ''" :src="imgSrc" style="width: 100px; height: 150px; margin-top: 10px;"></image>
</view>
</template>
<script>
import {
switchCamera,
captureImage,
getFrameBase64
} from "@/uni_modules/biming-camera"
export default {
data() {
return {
imgSrc: '',
currentCamera: 'back',
}
},
methods: {
onCameraError(e: any) {
console.error('相机组件出错:', e);
},
switchCm() {
switchCamera();
},
takePhoto() {
captureImage((base64: string) => {
this.imgSrc = 'data:image/jpeg;base64,' + base64;
});
},
getFrame() {
getFrameBase64((res: boolean, base64: string) => {
if (res) {
this.imgSrc = 'data:image/jpeg;base64,' + base64;
}
});
}
}
}
</script>
Android 权限配置
插件已在 uni_modules/biming-camera/utssdk/app-android/AndroidManifest.xml 中配置所需权限,无需手动添加。
<uses-permission android:name="android.permission.CAMERA" />
组件属性 (Props)
| 属性名 |
类型 |
默认值 |
说明 |
| defaultCamera |
String |
'back' |
默认开启的摄像头,可选值:'back' (后置), 'front' (前置) |
组件事件 (Events)
| 事件名 |
说明 |
回调参数 |
| error |
相机发生错误时触发 |
event: 错误对象 |
API
switchCamera()
切换前后摄像头。
- 调用方式:
- NVUE:
this.$refs.camera.switchCamera()
- UVUE:
import { switchCamera } from "@/uni_modules/biming-camera"; switchCamera();
- 参数: 无
- 返回值: 无
captureImage(callback)
执行拍照操作。照片数据将通过回调函数返回。
- 调用方式:
- NVUE:
this.$refs.camera.captureImage(callback)
- UVUE:
import { captureImage } from "@/uni_modules/biming-camera"; captureImage(callback);
- 参数:
callback: (base64: string) => void
- 拍照成功后的回调函数。
base64: 照片的 Base64 字符串 (JPEG 格式)。
- 返回值: 无
getFrameBase64(callback)
获取当前预览视图的快照。
- 调用方式:
- NVUE:
this.$refs.camera.getFrameBase64(callback)
- UVUE:
import { getFrameBase64 } from "@/uni_modules/biming-camera"; getFrameBase64(callback);
- 参数:
callback: (res: boolean, base64: string) => void
- 获取完成后的回调函数。
res: Boolean, 是否成功。
base64: 成功时为预览帧图像的 Base64 字符串 (JPEG 格式);失败时为错误信息。
- 返回值: 无