更新记录

4.01(2025-12-22)

1.修复 ios 开启相机无回调的问题 2.ios 加入自动闪光灯的支持

4.00(2025-11-17)

1.修复若干问题 2.增加了高清/标清切换、录像权限自动处理、iOS 高清录像、Android 自定义分辨率等大量新功能,欢迎体验。

3.26(2025-05-27)

紧急修复 ios 的 bug

查看更多

平台兼容性

Android Android CPU类型 iOS
适用版本区间:4.4 - 16.0 armeabi-v7a:支持,arm64-v8a:支持,x86:未测试 适用版本区间:11 - 18

原生插件通用使用流程:

  1. 购买插件,选择该插件绑定的项目。
  2. 在HBuilderX里找到项目,在manifest的app原生插件配置中勾选模块,如需要填写参数则参考插件作者的文档添加。
  3. 根据插件作者的提供的文档开发代码,在代码中引用插件,调用插件功能。
  4. 打包自定义基座,选择插件,得到自定义基座,然后运行时选择自定义基座,进行log输出测试。
  5. 开发完毕后正式云打包

付费原生插件目前不支持离线打包。
Android 离线打包原生插件另见文档 https://nativesupport.dcloud.net.cn/NativePlugin/offline_package/android
iOS 离线打包原生插件另见文档 https://nativesupport.dcloud.net.cn/NativePlugin/offline_package/ios

注意事项:使用HBuilderX2.7.14以下版本,如果同一插件且同一appid下购买并绑定了多个包名,提交云打包界面提示包名绑定不一致时,需要在HBuilderX项目中manifest.json->“App原生插件配置”->”云端插件“列表中删除该插件重新选择


自定义相机(CameraPreview)使用说明

感谢各位用户长期支持! 当前插件已升级到 4.0 版本,增加了高清/标清切换、录像权限自动处理、iOS 高清录像、Android 自定义分辨率等大量新功能,欢迎体验。最新版 demo.apk 可直接下载体验。

当前版本的 CameraPreview 组件已经覆盖旧 CameraPreviewPlus 的全部能力,老项目仅需把原来引用 CameraPreviewPlus 的位置改为 CameraPreview 即可,无需做额外兼容代码。

核心能力

  • 自定义相机 UI,可在 nvue 中自由排版
  • 拍照、自动裁剪、无声拍照、实时取色、变焦、曝光调节
  • 录像(含权限申请、保存、封面图)
  • 高清/标清切换、比例 16:9 / 4:3 / 1:1(Android)

快速使用

<template>
  <view class="page">
    <CameraPreview ref="camera"></CameraPreview>
  </view>
</template>
export default {
  methods: {
    startCamera() {
      this.$refs.camera.start({
        scale: '16:9',          // 4:3 / 16:9(Android 额外支持 1:1)
        hd: true,               // 高清模式,仅 iOS/Android 新版本有效
        noRecordPermissions: true, // 默认只申请相机,录像时另行申请麦克风(如果false,需要在hbuild里自己勾选READ_MEDIA_AUDIO、READ_MEDIA_VIDEO、RECORD_AUDIO权限)
        showSetting: true       // 没权限时是否提示去设置(仅android)
      }, res => console.log(res));
    },
    stopCamera() {
      this.$refs.camera.stop();
    }
  },
  onUnload() {
    this.$refs.camera.destroy();
  },
  onHide() {
    this.$refs.camera.stop();
  }
}

拍照示例

this.$refs.camera.takePhoto({
  quality: 90,           // 1-100,默认90
  width: 300,            // 默认300,传0取原图尺寸
  returnFile: false,     // 默认 false,true 则返回文件路径
  crop: [0, 0, 50, 50]   // 可不传,按百分比裁剪区域
}, res => {
  console.log('photo result', res);
});

无声拍照

// 1. 开启帧监听,开始持续拉取预览帧
this.$refs.camera.startFrameListen(res => console.log(res));
// 2. 需要无声拍照时拉取一帧,可重复调用
this.$refs.camera.getFrameData({
  quality: 60,        // 默认 90,可不传
  width: 400,         // 默认 300,0=原图
  crop: [0,0,50,50]   // 可选,按百分比裁剪
}, res => {
  console.log('frame base64', res.data);
});
// 3. 完成后停止监听以节省资源
this.$refs.camera.stopFrameListen(() => {});

录像

const savePath = plus.io.convertLocalFileSystemURL('_doc/video/');
this.$refs.camera.startRecord({
  profile: 5,         // 录像清晰度:1=High,3=Low,4=480P,5=720P,6=1080P,8=2160P
  savePath,           // 视频保存目录,需绝对路径
  orientation: 90     // iOS/部分后摄需传 90,默认 270(Android 后摄)
}, res => {
  if (res.code === 202) {
    // 首次授权,收到 202 后再次调用 startRecord
    this.$refs.camera.startRecord({ profile: 5, savePath, orientation: 90 }, () => {});
  }
});

this.$refs.camera.stopRecord(res => console.log('mp4', res.path, 'cover', res.coverImage));

其他常用接口

// 前后摄切换 + 闪光灯
this.$refs.camera.setIsbackCamera(true); // 后摄
this.$refs.camera.setFlash(true);        // 打开闪光灯
this.$refs.camera.setFlashAuto();        // 自动闪光灯(iOS/Android通用)

// 焦距与曝光
this.$refs.camera.setZoom(30);           // 0~99,默认 0
this.$refs.camera.getExposureCompensationVal(res => {
  const { min, max } = res.data;        // 当前设备的曝光范围
  this.$refs.camera.setExposureCompensation((min + max) / 2); // 将曝光设置到中间值
});

// 获特定位置的颜色
this.$refs.camera.getColor([50, 50], res => console.log('RGB', res.color));

Android 专属接口

// 1. 自动对焦 / 手动对焦 / 双指缩放
this.$refs.camera.autoFocus();
this.$refs.camera.startAutoFocus();  // 持续自动对焦
this.$refs.camera.cancelAutoFocus();
this.$refs.camera.startManualFocus();  // 启用手动对焦
this.$refs.camera.cancelManualFocus();
this.$refs.camera.startFingerZoom();  // 开启双指手势缩放
this.$refs.camera.cancelFingerZoom(); // 关闭手势缩放,恢复默认

// 2. 查询分辨率列表(默认取后置 cameraId=0)
this.$refs.camera.getCustomOptSize({}, res => console.log('preview sizes', res.data));
// res.data => [{width:1920,height:1080},{width:1280,height:720}, ...]
this.$refs.camera.getCustomPicSize({}, res => console.log('picture sizes', res.data));
this.$refs.camera.getCustomVideoSize({}, res => console.log('video sizes', res.data));

// 3. 手动设置分辨率并启动(示例为 1080p 预览/拍照/录像)
this.$refs.camera.setCameraConfigAndStart({
  customOptSize: { width: 1920, height: 1080 },   // 预览尺寸
  customPicSize: { width: 1920, height: 1080 },   // 拍照尺寸
  customVideoSize: { width: 1920, height: 1080 } // 录像尺寸
}, res => console.log(res));

// 4. FY-CameraPreview-FSYANG-PicTool(Android 模块)- 图片压缩工具
const PicTool = uni.requireNativePlugin('FY-CameraPreview-FSYANG-PicTool');
PicTool.compressImage({
  path: '/sdcard/DCIM/Camera/demo.jpg', // 必填,原图路径
  maxWidth: 1080,                       // 可选,等比限制最大宽
  maxHeight: 1080,                      // 可选,等比限制最大高
  quality: 80,                          // 1-100,默认80
  format: 'jpeg',                       // jpeg/png/webp,默认webp
  targetPath: '/sdcard/DCIM/Camera/demo_compress.jpg' // 可选,默认与原图同目录
}, res => {
  // { code:200, path:'/sdcard/...', msg:'compress success' }
  console.log('compress result', res);
});

如需更多场景或功能扩展,请联系作者(QQ:37894663)。购买后提供经典界面案例、远程协助与持续更新。旧版本用户可直接升级,原有调用方式保持兼容。***

隐私、权限声明

1. 本插件需要申请的系统权限列表:

相机

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

插件不采集任何数据

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率: