0

我正在关注 v4lvj 库上的教程,该库允许访问 linux 上的网络摄像头。指向源代码的链接我编写的示例程序基本上显示了您的网络摄像头的视频源。一切都按照程序描述的那样工作。当我尝试通过在视频源顶部添加一条绿线来更改程序时,问题就出现了。我只是以同样的方式抓取图形,设置线条颜色,然后绘制线条。

@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 bmp jpg 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

谁能告诉我为什么并帮我在视频提要上画一条线。谢谢你。

4

1 回答 1

0

您应该通过覆盖paint(Graphics g)方法进行绘画JLabel,然后进行铸造Graphics2D g2d = (Graphics2D) g;Graphics2D用于绘画。

在代码中使用 JLabel 的方式不正确。

您也可以使用BufferedImage从框架中收到的,获取它们Graphics并在其上绘制

于 2013-03-17T10:03:28.900 回答