2014-01-07 144 views
0

在這裏,我寫了一些代碼來使用java從USBcam捕捉圖像。com.github.sarxos.webcam.WebcamException:無法執行任務

下面是代碼:

Webcam webcam = Webcam.getDefault(); 
     webcam.open(); 
     try { 
      ImageIO.write(webcam.getImage(), "PNG", new File("d:/hello-world1.png")); 
      System.out.println(Thread.currentThread().getName()); 

     } catch (IOException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 

而且我已經添加了什麼都需要,但 運行應用程序時,圖像不饒人, 異常升高3罐。

以下是例外:

Exception in thread "main" com.github.sarxos.webcam.WebcamException: Cannot execute task 
    at com.github.sarxos.webcam.WebcamProcessor$AtomicProcessor.process(WebcamProcessor.java:57) 
    at com.github.sarxos.webcam.WebcamProcessor.process(WebcamProcessor.java:120) 
    at com.github.sarxos.webcam.WebcamTask.process(WebcamTask.java:35) 
    at com.github.sarxos.webcam.ds.cgt.WebcamOpenTask.open(WebcamOpenTask.java:20) 
    at com.github.sarxos.webcam.Webcam.open(Webcam.java:187) 
    at com.github.sarxos.webcam.Webcam.open(Webcam.java:147) 
    at ImageCapture.main(ImageCapture.java:16) 
Caused by: com.github.sarxos.webcam.WebcamException: Cannot start native grabber! 
    at com.github.sarxos.webcam.ds.buildin.WebcamDefaultDevice.open(WebcamDefaultDevice.java:220) 
    at com.github.sarxos.webcam.ds.cgt.WebcamOpenTask.handle(WebcamOpenTask.java:38) 
    at com.github.sarxos.webcam.WebcamProcessor$AtomicProcessor.run(WebcamProcessor.java:66) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) 
    at java.lang.Thread.run(Unknown Source) 

請建議我在哪裏,我把錯誤的想法。

回答

0
public class TakePictureExample { 
    public static void main(String[] args) throws IOException { 

     Webcam webcam = Webcam.getDefault(); 

     webcam.setViewSize(new Dimension(1024,768)); 

     webcam.open(false); 

     // get image 
     BufferedImage image = webcam.getImage(); 

     // save image to PNG file 
     ImageIO.write(image, "PNG", new File("test.png")); 
    } 
} 
+0

對不起@SSpoke我得到相同的異常 – user2996174

+0

嘗試註釋掉'webcam.setViewSize(新尺寸(1024,768));' – SSpoke

+0

好你的問題是'無法啓動本地採集'的https:// github上! com/sarxos/webcam-capture/blob/master/webcam -capture/src/main/java/com/github/sarxos/webcam/ds/buildin/WebcamDefaultDevice.java嘗試使'setViewSize'變小幫助看看這裏創建新的問題,https://github.com/sarxos/webcam-capture/issues – SSpoke