import { CameraSharp } from "@mui/icons-material"; import { Button, IconButton } from "@mui/material"; import Image from "next/image"; import React, { useRef } from "react"; import Webcam from "react-webcam"; interface WebcamCaptureProps { image: string | null; setImage: (image: string | null) => void; isWebcamVisible: boolean; setIsWebcamVisible: (isVisible: boolean) => void; } const WebcamCapture: React.FC = ({ image, setImage, isWebcamVisible, setIsWebcamVisible, }) => { const webcamRef = useRef(null); // Mengambil foto dari webcam const capture = () => { const image = webcamRef.current?.getScreenshot(); setIsWebcamVisible(false); setImage(image || null); }; const takePicture = () => { setImage(null); setIsWebcamVisible(true); }; // Mengatur ukuran webcam const videoConstraints = { width: 500, height: 480, facingMode: { exact: "environment" // untuk kamera belakang }, }; return (
{!isWebcamVisible && ( )} {isWebcamVisible && (
capture()}>
)} {image && (
Captured
)}
); }; export default WebcamCapture;