import React from "react";
import Webcam from './webcam.js'
export default function Camera() {
const renderCamera = () => {
Webcam.set({
width: 320,
height: 240,
image_format: "jpeg",
jpeg_quality: 90,
});
Webcam.attach("#my_camera");
};
const take_snapshot = () => {
// take snapshot and get image data
Webcam.snap(function (data_uri) {
// display results in page
document.getElementById("results").innerHTML =
"<h2>Here is your image:</h2>" + '<img src="' + data_uri + '"/>';
});
};
return (
<div className="App">
<h1>Image Capture</h1>
<button onClick={renderCamera}>open Camera</button>
<div id="my_camera"></div>
<div id="results">Your captured image will appear here...</div>
<button onClick={take_snapshot}>take a picture</button>
</div>
);
}
我在所有浏览器中都试过了,它在除 IE 之外的所有浏览器上都可以正常工作,请帮助我解决这个问题,谢谢。