克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

qr-camera

在线体验 | English

适用于浏览器的二维码扫描方案

功能

  1. 支持浏览器扫描二维码
  2. 支持拍照
  3. 支持录像功能
  4. 支持二维码解析和生成

quickstart

npm i qr-camera
import {QRCamera} from 'qr-camera';

async function main(){
    const camera = new QRCamera();
    document.body.appendChild(camera.video);
    console.log(await camera.scanQrcode());
}
main();

CDN

<body>
<script src="https://unpkg.com/qr-camera"></script>
<script>
    async function main(){
        const camera = new QRCamera();
        document.body.appendChild(camera.video);
        console.log(await camera.scanQrcode());
    }
    main();
</script>
</body>

API

1. QRCamera

const camera = new QRCamera(options);

options:

interface Options {
    video?: HTMLVideoElement; // 自定义video元素
    size?: { // video 元素宽高
        width: number;
        height: number;
    },
    useAudio?: boolean; // 是否开启音频
    cameraId?: string; // 指定摄像头启动
}

2. getCameras

获取摄像头列表

const cameras = await camera.getCameras();

3. switchCamera

切换摄像头

const result = await camera.switchCamera(cameraId); // 指定摄像头
const result = await camera.switchCamera(); // 切换下一个摄像头

4. scanQrcode

开启识别二维码

const content = await camera.scanQrcode({
    gap: 500 // 识别间隔,单位ms,默认为500ms
});

stopScanQrcode

停止识别二维码

camera.stopScanQrcode();

4. photo

拍照

const url = await camera.photo({
    base64: false, // 是否返回base64
    download: false, // 是否自动下载
    name: 'photo', // 下载的文件名
});

5. record

录像

const url = await camera.record({
    time: undefined, // 录像时长,默认为不限制,直到调用停止录像为止
    download: false, // 是否自动下载
    name: 'video', // 下载的文件名
});

pause

camera.pauseRecord();
camera.resumeRecord();
camera.recordPaused;

stop

camera.stopRecord();

qrcode

二维码能力请参考 tc-qrcode

import {qrcode} from 'qr-camera';
The MIT License (MIT) Copyright (c) 2019 - present Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

Web camera and QR code scanner 展开 收起
JavaScript 等 3 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化