我想用我的摄像头使用Java快照,并将其保存到JPG文件。 有什么步骤需要这样做? 一个教程将不胜感激。
问候,
布克哈德
JMF(Java Media Framework)是一个很好的起点。 但是,我没有成功。
我终于在这里找到了解决办法。
重要的部分是:
Buffer buf = frameGrabber.grabFrame(); // Convert frame to an buffered image so it can be processed and saved Image img = (new BufferToImage((VideoFormat) buf.getFormat()).createImage(buf)); buffImg = new BufferedImage(img.getWidth(this), img.getHeight(this), BufferedImage.TYPE_INT_RGB); //TODO saving the buffImg
您正在寻找的可能是Java媒体框架(JMF)。 请参阅Sun教程 。 我希望有帮助。
我更喜欢使用JMyron而不是JMF。 JMyron很容易使用访问摄像头。 要保存捕获的图像,只需使用ImageIO.write()保存BufferedImage; 这个博客文章如何使用网络摄像头使用Java是有用的开始使用JMyron。
尝试网络摄像头捕获项目。
此代码将从网络摄像头(嵌入式,连接到USB或IP摄像头)拍摄快照并将其保存为JPG文件:
Webcam webcam = Webcam.getDefault(); webcam.open() BufferedImage image = webcam.getImage(); ImageIO.write(image, "JPG", new File("test.jpg"));