日期:2014-05-19 浏览次数:20726 次
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); } }