网络摄像头找不到玩家:vfw:// 0 [英] Webcam Cannot find a Player for :vfw://0

查看:144
本文介绍了网络摄像头找不到玩家:vfw:// 0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的网络摄像头拍照,我刚开始使用JMF,我只需要使用网络摄像头拍摄照片,并将其保存到使用此代码的指定目录中。

  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;

/ *
*要更改此模板,请选择工具模板
*并在编辑器中打开模板。
* /

/ **
*
* @author victor
* /
public class WebCam {
public static void main(String [] args){
// TODO自动生成的方法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); //使用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);

组件视频= 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();
}
}
}

当我尝试运行我得到这个例外我是一个与JMF的菜鸟,所以请帮助...

  javax.media.NoPlayerException:找不到播放器for:vfw:// 0 
javax.media.Manager.createPlayerForContent(Manager.java:1412)
javax.media.Manager.createPlayer(Manager.java:417)
at javax.media.Manager.createRealizedPlayer(Manager.java:553)
at otro.proceso(WebCam.java:41)
在WebCam.main(WebCam.java:24)


解决方案

尝试这个

  package javasewebcam; 

import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;

import javax.imageio.ImageIO;
import javax.media.Buffer;
import javax.media.Manager;
import javax.media.MediaLocator;
import javax.media.Player;
import javax.media.control.FrameGrabbingControl;
import javax.media.format.VideoFormat;
import javax.media.util.BufferToImage;

public class CaptureScreenshot
{
private static Player player = null;
private static Image image = null;

public static void main(String [] args)
{
try
{
MediaLocator ml = new MediaLocator(vfw:// 0 );
player = Manager.createRealizedPlayer(ml);
player.start();
}
catch(Exception ex)
{
ex.printStackTrace();
System.exit(0);
}

while(image == null)
{
FrameGrabbingControl fgc =(FrameGrabbingControl)player.getControl(javax.media.control.FrameGrabbingControl);
缓冲区buf = fgc.grabFrame();

BufferToImage bi = new BufferToImage((VideoFormat)buf.getFormat());
image = bi.createImage(buf);

System.out.println(image+ image);
if(image!= null)
//(toBufferedImage(image));
//将图像保存在这里
image = null;
System.out.println(streaming);
}

try
{
ImageIO.write(toBufferedImage(image),png,new File(screenshot.png));
System.out.println(Image Saved!);
}
catch(Exception ex)
{
ex.printStackTrace();
System.exit(0);
}

player.close();
player.deallocate();
}


public static BufferedImage toBufferedImage(Image i)
{
BufferedImage bi = new BufferedImage(i.getWidth(null),i.getHeight (null),BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = bi.createGraphics();
g2d.drawImage(i,0,0,null);

return bi;
}

}


i'm tryin to take a picture in my webcam, i'm just starting to use JMF i just need to take a picture with a webcam and save it to a specified directory im using this code

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();
    }
}
}

when im trying to run i get this exception i'm a rookie with JMF so please help...

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)

解决方案

try with this

    package javasewebcam;

    import java.awt.Graphics2D;
    import java.awt.Image;
    import java.awt.image.BufferedImage;
    import java.io.File;

    import javax.imageio.ImageIO;
    import javax.media.Buffer;
    import javax.media.Manager;
    import javax.media.MediaLocator;
    import javax.media.Player;
    import javax.media.control.FrameGrabbingControl;
    import javax.media.format.VideoFormat;
    import javax.media.util.BufferToImage;

    public class CaptureScreenshot
    {
    private static Player player = null;
    private static Image image = null;

    public static void main(String[] args)
    {
        try
        {
            MediaLocator ml = new MediaLocator("vfw://0");
            player = Manager.createRealizedPlayer(ml);
            player.start();
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
            System.exit(0);
        }

        while (image == null)
        {
            FrameGrabbingControl fgc = (FrameGrabbingControl) player.getControl("javax.media.control.FrameGrabbingControl");
            Buffer buf = fgc.grabFrame();

            BufferToImage bi = new BufferToImage((VideoFormat) buf.getFormat());
            image = bi.createImage(buf);

                        System.out.println("image"+image);
                        if(image!=null)
                        //(toBufferedImage(image));
//save image in here 
                        image=null;
                        System.out.println("streaming");
        }

        try
        {
            ImageIO.write(toBufferedImage(image), "png", new File("screenshot.png"));
            System.out.println("Image Saved!");
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
            System.exit(0);
        }

        player.close();
        player.deallocate();
    }


    public static BufferedImage toBufferedImage(Image i)
    {
        BufferedImage bi = new BufferedImage(i.getWidth(null), i.getHeight(null), BufferedImage.TYPE_INT_ARGB);
        Graphics2D g2d = bi.createGraphics();
        g2d.drawImage(i, 0, 0, null);

        return bi;
    }

    }

这篇关于网络摄像头找不到玩家:vfw:// 0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆