小弟初学JAVA,最近在写一个摄像头控制的小程序
我是用了JMF的接口,那三个JAR文件都导入进工程了,
下面是我的大概程序:
private static Player player = null;
private CaptureDeviceInfo device = null;
private MediaLocator locator = null;
String str = "vfw:Microsoft WDM Image Capture (Win32):0";//这个是在JMF注册机中复制的
public DigitVedio() {
try {
Init();
}
catch (Exception e) {
e.printStackTrace();
}
}
private void Init() throws Exception
{//...............省略///
device = CaptureDeviceManager.getDevice(str2);
locator = device.getLocator();
///省略/////
}
主要问题好像是出在locator = device.getLocator();我把它注释掉后面就可以运行成功了,可是一放出来就
出错了,可以编译成功,可是无法运行成功,因为后面我写的有个窗体。
会不会是因为我用的免驱动的摄像头呢?
实在不知道是什么原因,希望各位大大指点下~~
谢谢啦~~~
------解决方案--------------------
你看 给你个例子 行吗?JMF我前些日子钻了一下 感觉java在这个上面很吃力 很高兴有人愿意学这个
- Java code
public class SampCam extends JFrame { /** * */ private static final long serialVersionUID = 1211056605389924001L; private static Player player = null; private CaptureDeviceInfo device = null; private MediaLocator locator = null; boolean proportion = true; String str1 = "vfw:Logitech USB Video Cam:0"; String str2 = "vfw:Microsoft WDM Image Capture (Win32):0"; Component component1; public SampCam() { super("摄像机"); try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());// 与操作系统风格一致 } catch (ClassNotFoundException e1) { e1.printStackTrace(); } catch (InstantiationException e1) { e1.printStackTrace(); } catch (IllegalAccessException e1) { e1.printStackTrace(); } catch (UnsupportedLookAndFeelException e1) { e1.printStackTrace(); } try { jbInit(); } catch (Exception e) { e.printStackTrace(); } } public static void main(String[] args) { new SampCam(); } private void jbInit() throws Exception { component1 = Box.createGlue(); // =====================初始化设备===================// component1.addNotify(); device = CaptureDeviceManager.getDevice(str2); locator = device.getLocator(); try { player = Manager.createRealizedPlayer(locator); player.start(); if ((component1 = player.getVisualComponent()) != null) { this.getContentPane().add(component1, "Center"); } } catch (Exception e) { e.printStackTrace(); } component1.setBounds(new Rectangle(0,0, 250, 280)); this.setSize(380, 300); this.setVisible(true); }}