更新记录
1.1.0(2026-09-27)
新增三端(Android/iOS/HarmonyOS)原生相机组件:任意布局预览、静默拍照、录像(含收音)、文字与时间水印叠加、连拍批量回图、前后摄切换、手电筒闪光灯。新增 addWatermark / compressImage / getImageInfo 静态 API。Android 拍照链路稳定、照片同步写入系统相册(Pictures/MJCC)。
平台兼容性
uni-app x(4.21)
| Chrome |
Safari |
Android |
Android插件版本 |
iOS |
iOS插件版本 |
鸿蒙 |
鸿蒙插件版本 |
微信小程序 |
| × |
× |
√ |
1.1.0 |
√ |
1.1.0 |
√ |
1.1.0 |
× |
mj-custom-camera 自定义相机 · 水印相机(Android / iOS / HarmonyOS)
版本 v1.1.0 · 三端全功能 · 普通授权版 29.9 元 / 源码授权版 99 元
任意布局相机预览组件 + 图片水印/压缩能力,三端原生实现,兼容 uni-app 与 uni-app x。
功能特性
| 能力 |
Android |
iOS |
HarmonyOS |
| 任意布局相机预览(native-view 嵌入原生相机) |
✅ |
✅ |
✅ |
| 静默拍照(无快门声抓帧) |
✅ |
✅ |
✅ |
| 录像 |
✅ |
✅ |
✅ |
| 文字水印叠加(含时间水印) |
✅ |
✅ |
✅ |
| 连拍批量回图 |
✅ |
✅ |
✅ |
| 图片压缩 |
✅ |
✅ |
✅ |
| 图片信息 |
✅ |
✅ |
✅ |
| 切换前后摄像头 / 闪光灯 |
✅ |
✅ |
✅ |
安装
- 将本插件目录(
mj-custom-camera)拷贝到项目 uni_modules 目录下。
- HBuilderX 中右键
uni_modules/mj-custom-camera → 从插件市场更新(或直接使用本地目录)。
组件用法(任意布局相机)
<template>
<view style="flex: 1;">
<mj-custom-camera
ref="cameraRef"
style="flex: 1;"
mode="photo"
position="back"
:flash="false"
watermarkText="我的水印"
:watermarkEnabled="true"
@photo="onPhoto"
@recordFinish="onRecordFinish"
@error="onError"
@ready="onReady">
</mj-custom-camera>
<button @click="takePhoto">拍照</button>
<button @click="burst">连拍5张</button>
</view>
</template>
<script setup lang="uts">
const cameraRef = ref<MjCustomCameraComponentPublicInstance | null>(null)
function takePhoto() {
cameraRef.value?.takePhoto()
}
function burst() {
cameraRef.value?.burstCapture(5)
}
function onPhoto(e: UniNativeViewEvent) {
// e.detail.tempFilePath 为拍照结果路径(含水印)
console.log('拍照结果', e.detail)
}
function onRecordFinish(e: UniNativeViewEvent) {
console.log('录像完成', e.detail)
}
function onError(e: UniNativeViewEvent) {
console.log('错误', e.detail.errCode, e.detail.errMsg)
}
function onReady(e: UniNativeViewEvent) {
console.log('相机就绪')
}
</script>
组件属性(props)
| 属性 |
类型 |
默认 |
说明 |
| mode |
string |
'photo' |
拍摄模式:photo / video |
| position |
string |
'back' |
摄像头:back / front |
| flash |
boolean |
false |
是否开启闪光灯 |
| watermarkText |
string |
'' |
水印文字,为空时仅追加时间水印 |
| watermarkEnabled |
boolean |
true |
是否开启水印 |
组件方法
| 方法 |
说明 |
| takePhoto() |
拍照一张(静默抓帧,返回水印后图片) |
| startRecord() |
开始录像(需 mode='video') |
| stopRecord() |
停止录像并返回文件 |
| burstCapture(count) |
连拍 count 张(1-20),逐张回调 |
| switchCamera() |
切换前后摄像头(Android 按设备摄像头列表轮换) |
| setFlash(enable) |
开关闪光灯 |
组件事件
| 事件 |
说明 |
| @photo |
拍照成功,e.detail:{ tempFilePath, width, height, burstLeft } |
| @recordFinish |
录像完成,e.detail:{ tempFilePath } |
| @error |
出错,e.detail:{ errCode, errMsg } |
| @ready |
相机初始化完成 |
静态 API 用法(图片水印 / 压缩)
import { addWatermark, compressImage, getImageInfo } from "@/uni_modules/mj-custom-camera"
// 给图片加时间+文字水印
addWatermark({
filePath: "/storage/emulated/0/.../photo.jpg",
text: "旅行记录",
time: true,
position: "rightBottom",
fontSize: 40,
color: "#FFFFFFFF",
opacity: 0.8
}, (res) => {
console.log("水印图:", res.tempFilePath)
}, (err) => {
console.log("失败:", err.errCode, err.errMsg)
})
// 压缩图片
compressImage({
filePath: "/storage/emulated/0/.../photo.jpg",
quality: 80,
maxWidth: 1280,
maxHeight: 1280
}, (res) => {
console.log("压缩后:", res.tempFilePath, res.size)
}, (err) => {
})
// 图片信息
getImageInfo("/storage/emulated/0/.../photo.jpg", (res) => {
console.log(res.width, res.height, res.size)
}, (err) => {
})
错误码
| errCode |
说明 |
| 9001001 |
相机不可用或未找到相机设备 |
| 9001002 |
相机/麦克风权限被拒绝 |
| 9001003 |
拍照失败 |
| 9001004 |
录像失败 |
| 9001005 |
文件保存失败 |
| 9001006 |
连拍失败 |
| 9001007 |
参数错误 |
| 9001008 |
当前平台暂不支持该能力 |
权限说明
- Android:相机权限、录音权限(录像时),运行时由插件自动申请
- iOS:相机权限、麦克风权限(录像时),首次使用自动申请
- HarmonyOS:
ohos.permission.CAMERA、ohos.permission.MICROPHONE(录像时)
隐私与数据
本插件不采集任何数据,拍摄的照片与视频仅保存在用户设备本地,无任何网络请求。
版本记录
见 changelog.md。