2.0.0 • Published 4 years ago

capture-pic v2.0.0

Weekly downloads
84
License
-
Repository
-
Last release
4 years ago

Capture photo Util

Usage

  <!DOCTYPE html>
  <html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>vue</title>
  </head>
  <body>
    <div id="app">
      <div>
        <h2>直接抓拍</h2>
        <button id="capture">抓拍</button>
      </div>
      <div>
        <h2>video预览</h2>
        <button id="preview">预览</button>
        <button id="stop">停止</button>
      </div>
      <div>
        <video id="video"></video>
      </div>
      <div>
        <img id="img" />
      </div>
    </div>
  </body>
  </html>

typescript

import { CapturePic } from 'capture-pic';
export interface Options {
  videoId: string;
  width: number;
  height: number;
}

let capUtil: CapturePic;
const button = document.getElementById('capture');
if(button){
  button.onclick = async (): Promise<void> =>{
    if(!capUtil){
      capUtil = await new CapturePic().init();
    }
    if(!capUtil.isSuportTest()){
      console.error('不支持抓拍功能');
      capUtil = null
      return
    }
    const img: HTMLImageElement = document.getElementById('img') as HTMLImageElement;
    img.src = capUtil.capture().getBase64();
    capUtil.stop();
    capUtil = null;
  }
}

const preview = document.getElementById('preview');
if(preview){
  preview.onclick = async (): Promise<void> =>{
    if(!capUtil){
      capUtil = await new CapturePic({
        videoId:'video'
      } as Options).init();
    }
    if(!capUtil.isSuportTest()){
      console.error('不支持抓拍功能');
      capUtil = null
      return
    }
    const img: HTMLImageElement = document.getElementById('img') as HTMLImageElement;
    img.src = capUtil.capture().getBase64();
  }
}
const stop = document.getElementById('stop');
if(stop){
  stop.onclick = (): void =>{
    if(!capUtil){
      return;
    }
    capUtil.stop();
    capUtil = null;
  }
}

ES6用法也类似,不赘述

2.0.0

4 years ago

1.0.23

4 years ago

1.0.22

4 years ago

1.0.21

4 years ago

1.0.20

4 years ago

1.0.19

4 years ago

1.0.18

4 years ago

1.0.2

4 years ago

1.0.17

4 years ago

1.0.16

4 years ago

1.0.9

4 years ago

1.0.7

4 years ago

1.0.4

4 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.15

4 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.0

4 years ago

0.0.87

4 years ago

0.0.9

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago