자바만 되고 php는 왜안되지 흑흑 > 자유게시판

자유게시판

자바만 되고 php는 왜안되지 흑흑 정보

자바만 되고 php는 왜안되지 흑흑

본문

package webCam;

 

import java.awt.BorderLayout;

import java.awt.event.ItemEvent;

import java.awt.event.ItemListener;

import java.awt.event.WindowEvent;

import java.awt.event.WindowListener;

import java.lang.Thread.UncaughtExceptionHandler;

 

import javax.swing.JFrame;

import javax.swing.SwingUtilities;

 

import com.github.sarxos.webcam.Webcam;

import com.github.sarxos.webcam.WebcamDiscoveryEvent;

import com.github.sarxos.webcam.WebcamDiscoveryListener;

import com.github.sarxos.webcam.WebcamEvent;

import com.github.sarxos.webcam.WebcamListener;

import com.github.sarxos.webcam.WebcamPanel;

import com.github.sarxos.webcam.WebcamPicker;

import com.github.sarxos.webcam.WebcamResolution;

 

/**

 * Proof of concept of how to handle webcam video stream from Java

 * 

 * @author Bartosz Firyn (SarXos)

 */

public class WebcamViewerExample extends JFrame implements Runnable, WebcamListener, WindowListener,

        UncaughtExceptionHandler, ItemListener, WebcamDiscoveryListener {

 

    private Webcam webcam = null;

    private WebcamPanel panel = null;

    private WebcamPicker picker = null;

 

    @Override

    public void run() {

 

        Webcam.addDiscoveryListener(this);

        setTitle("Java Webcam Capture POC");

        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        setLayout(new BorderLayout());

 

        addWindowListener(this);

 

        picker = new WebcamPicker();

        picker.addItemListener(this);

 

        webcam = picker.getSelectedWebcam();

 

        if (webcam == null) {

            System.out.println("No webcams found...");

            System.exit(1);

        }

 

        webcam.setViewSize(WebcamResolution.VGA.getSize());

        webcam.addWebcamListener(WebcamViewerExample.this);

 

        panel = new WebcamPanel(webcam, false);

        panel.setFPSDisplayed(true);

 

        add(picker, BorderLayout.NORTH);

        add(panel, BorderLayout.CENTER);

 

        pack();

        setVisible(true);

 

        Thread t = new Thread() {

 

            @Override

            public void run() {

                panel.start();

            }

        };

        t.setName("example-starter");

        t.setDaemon(true);

        t.setUncaughtExceptionHandler(this);

        t.start();

    }

 

    public static void main(String[] args) {

        SwingUtilities.invokeLater(new WebcamViewerExample());

    }

 

    @Override

    public void webcamOpen(WebcamEvent we) {

        System.out.println("webcam open");

    }

 

    @Override

    public void webcamClosed(WebcamEvent we) {

        System.out.println("webcam closed");

    }

 

    @Override

    public void webcamDisposed(WebcamEvent we) {

        System.out.println("webcam disposed");

    }

 

    @Override

    public void webcamImageObtained(WebcamEvent we) {

        // do nothing

    }

 

    @Override

    public void windowActivated(WindowEvent e) {

    }

 

    @Override

    public void windowClosed(WindowEvent e) {

        webcam.close();

    }

 

    @Override

    public void windowClosing(WindowEvent e) {

    }

 

    @Override

    public void windowOpened(WindowEvent e) {

    }

 

    @Override

    public void windowDeactivated(WindowEvent e) {

    }

 

    @Override

    public void windowDeiconified(WindowEvent e) {

        System.out.println("webcam viewer resumed");

        panel.resume();

    }

 

    @Override

    public void windowIconified(WindowEvent e) {

        System.out.println("webcam viewer paused");

        panel.pause();

    }

 

    @Override

    public void uncaughtException(Thread t, Throwable e) {

        System.err.println(String.format("Exception in thread %s", t.getName()));

        e.printStackTrace();

    }

 

    @Override

    public void itemStateChanged(ItemEvent e) {

        if (e.getItem() != webcam) {

            if (webcam != null) {

 

                panel.stop();

 

                remove(panel);

 

                webcam.removeWebcamListener(this);

                webcam.close();

 

                webcam = (Webcam) e.getItem();

                webcam.setViewSize(WebcamResolution.VGA.getSize());

                webcam.addWebcamListener(this);

 

                System.out.println("selected " + webcam.getName());

 

                panel = new WebcamPanel(webcam, false);

                panel.setFPSDisplayed(true);

 

                add(panel, BorderLayout.CENTER);

                pack();

 

                Thread t = new Thread() {

 

                    @Override

                    public void run() {

                        panel.start();

                    }

                };

                t.setName("example-stoper");

                t.setDaemon(true);

                t.setUncaughtExceptionHandler(this);

                t.start();

            }

        }

    }

 

    @Override

    public void webcamFound(WebcamDiscoveryEvent event) {

        if (picker != null) {

            picker.addItem(event.getWebcam());

        }

    }

 

    @Override

    public void webcamGone(WebcamDiscoveryEvent event) {

        if (picker != null) {

            picker.removeItem(event.getWebcam());

        }

    }

}

추천
0

댓글 2개

웹캠 실행코드인걸로 보이네요

http://www.vivekmoyal.in/webcam-in-php-how-to-use-webcam-in-php/

참고해보세요
전체 189,496 |RSS
자유게시판 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIR SOFT