
java调用摄像头进行拍照和保存
发布日期:2022-03-08 21:50:44
浏览次数:2
分类:技术文章
本文共 3263 字,大约阅读时间需要 10 分钟。
简单记录一下步骤,为了以后使用时方便。
1.创建一个springboot项目,pom依赖为``org.springframework.boot spring-boot-starter-jdbc mysql mysql-connector-java runtime org.projectlombok lombok true ** ** org.springframework.boot spring-boot-starter-test test com.github.sarxos webcam-capture 0.3.12 org.springframework.boot spring-boot-maven-plugin org.projectlombok lombok
2.写一个测试类,代码为
package com.example.shexiangtou;import com.github.sarxos.webcam.Webcam;import com.github.sarxos.webcam.WebcamPanel;import com.github.sarxos.webcam.WebcamResolution;import com.github.sarxos.webcam.WebcamUtils;import com.github.sarxos.webcam.util.ImageUtils;import javax.swing.*;import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;public class TestWebCam { private static JFrame window; public static void main(String[] args) throws InterruptedException { Webcam webcam = Webcam.getDefault(); webcam.setViewSize(WebcamResolution.VGA.getSize()); WebcamPanel panel = new WebcamPanel(webcam); panel.setFPSDisplayed(true); panel.setDisplayDebugInfo(true); panel.setImageSizeDisplayed(true); panel.setMirrored(true); JFrame window = new JFrame("张世鹏的拍照小程序"); window.add(panel); window.setResizable(true); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window.pack(); window.setVisible(true); final JButton button = new JButton("点击进行拍照"); window.add(panel, BorderLayout.CENTER); window.add(button, BorderLayout.SOUTH); window.setResizable(true); window.pack(); window.setVisible(true); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { button.setEnabled(false); //设置按钮不可点击 //实现拍照保存-------start String fileName = "D://" + System.currentTimeMillis(); **//保存路径即图片名称(不用加后缀)** WebcamUtils.capture(webcam, fileName, ImageUtils.FORMAT_PNG); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { JOptionPane.showMessageDialog(null, "拍照成功"); button.setEnabled(true); //设置按钮可点击 return; } }); //实现拍照保存-------end } }); }}
转载地址:https://blog.csdn.net/m0_55627541/article/details/121457440 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
路过,博主的博客真漂亮。。
[***.116.15.85]2023年09月10日 03时59分24秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
c++ malloc calloc new [] 及差异
2019-03-07
memset memcpy
2019-03-07
c++ memcpy 快
2019-03-07
c++ strcat
2019-03-07
c++ 冒泡排序、鸡尾酒
2019-03-07
c/c++ 崩溃原因。
2019-03-07
构造函数不写业务逻辑
2019-03-07
window nginx 配置
2019-03-07
dll热更新
2019-03-07
c++ 链表 详解 for应用
2019-03-07
svnadmin 不是内部命令 一招搞定
2019-03-07
error LNK2001: 无法解析的外部符号 “public: virtual
2019-03-07
c++ 自动增长数组 动态数组
2019-03-07
当前不会命中断点,还没有为文档加载任何符号。c++ vs
2019-03-07
程序优化进阶篇(适合各种编程语言)
2019-03-07
GDAL 拼接 镶嵌 投影 shp裁剪
2019-03-07
c++模板类静态成员初始化
2019-03-07
去除百度地图logo
2019-03-07
c++ 信息雨
2019-03-07