java - 如何使用java将图像保存在磁盘上的文件夹中

标签 java image netbeans-7 javax.imageio

我想将图像保存在磁盘上,例如 c:/images,该图像是使用 java 的网络摄像头捕获的。我想再次将该图像作为标签显示在 JForm 上... 使用 java 和 netbeans 可以吗 我是java新手

最佳答案

您可以保存图像

private static void save(String fileName, String ext) {

   File file = new File(fileName + "." + ext);
   BufferedImage image = toBufferedImage(file);
try {
   ImageIO.write(image, ext, file);  // ignore returned boolean
} catch(IOException e) {
 System.out.println("Write error for " + file.getPath() +
                               ": " + e.getMessage());
  }
 }

并从磁盘读取图像并显示到标签中

File file = new File("image.gif");
    image = ImageIO.read(file);
JFrame frame = new JFrame();
JLabel label = new JLabel(new ImageIcon(image));
frame.getContentPane().add(label, BorderLayout.CENTER);
frame.pack();
frame.setVisible(true);

关于java - 如何使用java将图像保存在磁盘上的文件夹中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10897221/

相关文章:

image - 如何验证此 URL 重定向到图像?

installation - 在 NetBeans 安装程序中包含( bundle )JRE?

java - 在 Java 1.7 中第一次对 TreeSet 进行 add 调用时触发了compareTo

java - 机器人类的关键事件

java - 如何在没有 Math#round 的情况下进行舍入?

mysql - 直接将图像存储在数据库中还是作为base64数据?

java - 哪些 SWING 元素可以添加到 ButtonGroup 中才有意义?

html - 如何制作只影响文本而不影响图像的 CSS 规则?

java - 连接 MYSQL 和 netbeans 7.4

java - 查找Netbeans中设置的主项目的路径