0

Web カメラで写真を撮ろうとしています。JMF を使い始めたばかりです。Web カメラで写真を撮り、指定されたディレクトリに保存する必要があるだけです。このコードを使用しています。

import java.awt.Component;
import javax.media.Manager;
import javax.media.MediaLocator;
import javax.media.Processor;
import javax.media.protocol.FileTypeDescriptor;
import javax.swing.JFrame;
import javax.swing.JLabel;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author victor
 */
public class WebCam {
public static void main(String[] args) {
// TODO Auto-generated method stu
    otro perro=new otro();
    perro.show();
    perro.proceso();
}
}
class otro extends JFrame{
JLabel Imagen;
otro(){
    Imagen=new JLabel();
    Imagen.setBounds(30,40,20,20);
    add(Imagen);
    setBounds(400,400,400,400);
    setLayout( null ); // use a BorderLayou  
    setTitle("Prueba de Camara Web");
}
public void proceso(){
        Manager.setHint( Manager.LIGHTWEIGHT_RENDERER, true );
    try{
        MediaLocator ml = new MediaLocator("vfw://0");
        Player p = (Player) Manager.createRealizedPlayer(ml);

        Component video = p.getVisualComponent();

        video.setBounds(20,30,600,600);
        if ( video != null ){
            // agragar el video al componente
            add( video);
        }


        p.start();
    }catch(Exception e){
        e.printStackTrace();
    }
}
}

上記を実行すると、次の例外が発生します。

javax.media.NoPlayerException: Cannot find a Player for :vfw://0
at javax.media.Manager.createPlayerForContent(Manager.java:1412)
at javax.media.Manager.createPlayer(Manager.java:417)
at javax.media.Manager.createRealizedPlayer(Manager.java:553)
at otro.proceso(WebCam.java:41)
at WebCam.main(WebCam.java:24)
4

1 に答える 1