2012-06-05 69 views
1

我想将图像保存在磁盘上,例如c:/ images,这是使用java ..捕获的网络摄像头,并且我想在JForm上将该图像显示为标签... 这是可能的使用Java和NetBeans 我在Java如何使用java将磁盘上的图像保存到磁盘上的文件夹

+0

听起来好像要*负载*图像从磁盘。顺便说一句,你在这里使用的是哪个版本的netbeans-7? – aioobe

+1

是的,这是可能的。 :) –

+0

使用此链接[阅读/用Java加载图像](http://docs.oracle.com/javase/tutorial/2d/images/loadimage.html) –

回答

1

可以保存图像

private static void save(BufferedImage image, 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); 
1

您可以使用BufferedImage中从硬盘加载图像新:

BufferedImage img = null; 
try { 
    img = ImageIO.read(new File("strawberry.jpg")); 
} catch (IOException e) { 
} 

尝试此链接以获取更多信息。 Reading/Loading Images in Java

而这一个用于保存图像。 Writing/Saving an Image

try { 
    // retrieve image 
    BufferedImage bi = getMyImage(); 
    File outputfile = new File("saved.png"); 
    ImageIO.write(bi, "png", outputfile); 
} catch (IOException e) { 
    ... 
} 
-1
//Start Photo Upload with No// 
    if (simpleLoanDto.getPic() != null && simpleLoanDto.getAdharNo() != null) { 
     String ServerDirPath = globalVeriables.getAPath() + "\\"; 
     File ServerDir = new File(ServerDirPath); 
     if (!ServerDir.exists()) { 
      ServerDir.mkdirs(); 
     } 
     // Giving File operation permission for LINUX// 
     IOperation.setFileFolderPermission(ServerDirPath); 
     MultipartFile originalPic = simpleLoanDto.getPic(); 
     byte[] ImageInByte = originalPic.getBytes(); 
     FileOutputStream fosFor = new FileOutputStream(
       new File(ServerDirPath + "\\" + simpleLoanDto.getAdharNo() + "_"+simpleLoanDto.getApplicantName()+"_.jpg")); 
     fosFor.write(ImageInByte); 
     fosFor.close(); 
    } 
    //End Photo Upload with No//