更新记录

1.0.2(2024-01-26)

优化

1.0.1(2024-01-26)

优化

1.0.0(2024-01-26)

初版上线

查看更多

平台兼容性

Vue2 Vue3
× ×
App 快应用 微信小程序 支付宝小程序 百度小程序 字节小程序 QQ小程序
HBuilderX 3.7.0,Android:支持,iOS:不支持 × × × × × ×
钉钉小程序 快手小程序 飞书小程序 京东小程序
× × × ×
H5-Safari Android Browser 微信浏览器(Android) QQ浏览器(Android) Chrome IE Edge Firefox PC-Safari
× × × × × × × × ×

xiexie-camera 开发文档

1.在nvue文件中使用

  <yy-texture-view :style="{width:width,height:height}" @available="onViewAvailable()"  ></yy-texture-view>

2.开放的方法

方法 描述 参数
requestPermissionCamera 相机权限申请
getCameras 获取摄像头列表
getSupportedPreviewSizesByCameraId 获取支持的相机预览分辨率 id //摄像头id
openCamera 打开摄像头 id //需要打开的摄像头id
getSupportedPictureSizesByCameraId 获取支持的拍照图片分辨率 id //摄像头id
closeCamera 关闭摄像头 id //当前打开的摄像头id
takePicture 拍照 id //指定拍照的摄像头id
width //设置摄像头支持的图片分辨率
height //设置摄像头支持的图片分辨率
base64: true //是否返回base64图片
quailty: 100 //图片质量
path:null //图片存储路径(如设置base64:true,该路径配置不生效)

demo

 <template>
    <view>

        <yy-texture-view :style="{width:width,height:height}" @available="onViewAvailable()"  ></yy-texture-view>

        <button @click="_quanxian()">权限申请</button>
        <button @click="_getCameras()">获取摄像头列表</button>
        <button @click="_getSupportedPreviewSizesByCameraId('1')">获取支持的预览分辨率</button>
        <button @click="_getSupportedPictureSizesByCameraId('1')">获取支持的拍照图片分辨率</button>
        <button @click="_openCamera('0')">打开摄像头(后摄像头)</button>
        <button @click="_openCamera('1')">打开摄像头(前置摄像头)</button>
        <button @click="_closeCamera()">关闭已经打开的摄像头</button>
        <button @click="_takePicture()">拍照</button>

    </view>
</template>

<script>

    import {
         requestPermissionCamera,
        getSupportedPreviewSizesByCameraId,
        getSupportedPictureSizesByCameraId,
        openCamera,
        getCameras,
        closeCamera,
        takePicture

    } from "@/uni_modules/xiexie-camera";

    function showConsole(data) {
        uni.showModal({
            content: JSON.stringify(data)
        })
    }

    export default {
        data() {
            return {
                height: 160,
                width: 120,
                cameraId: ""
            }
        },
        methods: {
            async _quanxian() {
                try {
                    console.log( await requestPermissionCamera());
                } catch (e) {
                    showConsole(e);
                }
            },
            async _openCamera(_id) {
                try {
                    let size = getSupportedPreviewSizesByCameraId(_id);
                    await openCamera({
                        id: _id,
                        previewWidth: size[0].width,
                        previewHeight: size[0].height
                    });
                    this.cameraId = _id;

                } catch (e) {
                    showConsole(e)
                }

            },
            async _closeCamera() {
                if (this.cameraId.length > 0) {
                    try {
                        await closeCamera(this.cameraId);
                    } catch (e) {
                        showConsole(e.message.toString())
                    }
                }
            },
            async _takePicture() {
                if (this.cameraId.length > 0) {
                    try {
                        let size = getSupportedPictureSizesByCameraId(this.cameraId);

                        let path = await takePicture( {
                            id:this.cameraId,
                            width: size[0].width,
                            height: size[0].height,
                            base64: true,
                            quailty: 100,
                            path:null
                        });

                        uni.previewImage({
                            urls: [path],
                            current: 0
                        });
                        //showConsole(path);

                    } catch (e) {
                        showConsole(e.message.toString())
                    }
                }
            },
            _getCameras() {
                let sss = getCameras();
                showConsole(sss);
            },
            _getSupportedPreviewSizesByCameraId(id) {
                showConsole(getSupportedPreviewSizesByCameraId(id));
            },
            _getSupportedPictureSizesByCameraId(id) {
                showConsole(getSupportedPictureSizesByCameraId(id));
            },
            onViewAvailable() {
                //showConsole("onViewAvailable");
            }

        }
    }
</script>

<style>

</style>

隐私、权限声明

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

<uses-permission android:name="android.permission.CAMERA" />

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

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

暂无用户评论。

使用中有什么不明白的地方,就向插件作者提问吧~ 我要提问