2012-09-05 27 views
0

我正在關注允許訪問linux上的網絡攝像頭的v4lvj庫教程。 link to source我編寫了一個基本顯示webcamera視頻源的示例程序。一切正如程序所述。當我嘗試通過在視頻輸入的頂部添加綠線來更改程序時,問題就出現了。我只需用相同的方法抓住圖形,設置線條顏色,然後繪製線條。v4lvj在網絡攝像頭上繪製線條

@Override 
     public void nextFrame(VideoFrame frame) { 
       // This method is called when a new frame is ready. 
       // Don't forget to recycle it when done dealing with the frame. 

       // draw the new frame onto the JLabel 
       label.getGraphics().drawImage(frame.getBufferedImage(), 0, 0, width, height, null); 
       label.getGraphics().setColor(Color.GREEN); //this line causes exceptions 
       label.getGraphics().drawLine(0, 0, 640, 480); //this line causes exceptions 

       // recycle the frame 
       frame.recycle(); 
     } 

當我這樣做,雖然,我得到一些例外前面有「看來你的JVM不能將此圖像支持的圖像類型的解碼:BMP JPG BMP JPG ...」,然後

javax.imageio.IIOException: Unsupported marker type 0x5a 
    at com.sun.imageio.plugins.jpeg.JPEGImageReader.readImage(Native Method) 
    at com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal(JPEGImageReader.java:1176) 
    at com.sun.imageio.plugins.jpeg.JPEGImageReader.read(JPEGImageReader.java:984) 
    at javax.imageio.ImageIO.read(ImageIO.java:1438) 
    at javax.imageio.ImageIO.read(ImageIO.java:1342) 
    at au.edu.jcu.v4l4j.JPEGVideoFrame.refreshBufferedImage(Unknown Source) 
    at au.edu.jcu.v4l4j.BaseVideoFrame.getBufferedImage(Unknown Source) 
    at SimpleViewer.nextFrame(SimpleViewer.java:143) 
    at au.edu.jcu.v4l4j.PushSource.run(Unknown Source) 
    at java.lang.Thread.run(Thread.java:679) 
au.edu.jcu.v4l4j.exceptions.V4L4JException: Exception received while grabbing next frame 
    at au.edu.jcu.v4l4j.PushSource.run(Unknown Source) 
    at java.lang.Thread.run(Thread.java:679) 
Caused by: au.edu.jcu.v4l4j.exceptions.UnsupportedMethod: Unable to decode the image 
    at au.edu.jcu.v4l4j.JPEGVideoFrame.refreshBufferedImage(Unknown Source) 
    at au.edu.jcu.v4l4j.BaseVideoFrame.getBufferedImage(Unknown Source) 
    at SimpleViewer.nextFrame(SimpleViewer.java:143) 
    ... 2 more 
Caused by: javax.imageio.IIOException: Unsupported marker type 0x5a 
    at com.sun.imageio.plugins.jpeg.JPEGImageReader.readImage(Native Method) 
    at com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal(JPEGImageReader.java:1176) 
    at com.sun.imageio.plugins.jpeg.JPEGImageReader.read(JPEGImageReader.java:984) 
    at javax.imageio.ImageIO.read(ImageIO.java:1438) 
    at javax.imageio.ImageIO.read(ImageIO.java:1342) 
    ... 5 more 

任何人都可以告訴我爲什麼,並幫助我在視頻Feed的頂部畫一條線。謝謝。

+0

最重要的是,即使我刪除這兩條線,該計劃將繼續終止以同樣的方式,直到我拔掉,並然後在網絡攝像頭中重新插入 – Matthew

+0

您是否曾經解決過這個問題? –

+0

我還沒有,但我還沒有看過它在一段時間... – Matthew

回答

0

你應該做你的畫通過重寫的JLabelpaint(Graphics g)方法, 然後做一個鑄件Graphics2D g2d = (Graphics2D) g;和使用Graphics2D繪畫。

這是您在代碼中使用JLabel的不正確方法。

你也使用BufferedImage您從幀收到,得到他們的Graphics並在其上繪製