如何使用java将图像保存在磁盘上的文件夹中 [英] how to save the the image in folder on disk using java

查看:311
本文介绍了如何使用java将图像保存在磁盘上的文件夹中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将图像保存在磁盘上,例如 c:/images 使用 java..这是否可以使用 java 和 netbeans我是 Java 新手

I want to save the image on disk such as c:/images which is captured by webcam using java ..and again I want to display that image on JForm as a label... is this possible using java and netbeans I'm new in 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());
  }
 }

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

and read image from disk and show into label as

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将图像保存在磁盘上的文件夹中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆