如何使用java将映像保存在磁盘上的文件夹中
我想将该图像保存在磁盘上,如使用java的网络摄像头捕获的c:/images。我想再次将该图像显示在JForm上作为标签。。。 使用java和netbeans是否可以做到这一点如何使用java将映像保存在磁盘上的文件夹中,java,image,netbeans-7,javax.imageio,Java,Image,Netbeans 7,Javax.imageio,我想将该图像保存在磁盘上,如使用java的网络摄像头捕获的c:/images。我想再次将该图像显示在JForm上作为标签。。。 使用java和netbeans是否可以做到这一点 我是java新手您可以使用BuffereImage从硬盘加载映像: BufferedImage img = null; try { img = ImageIO.read(new File("strawberry.jpg")); } catch (IOException e) { } 请尝试此链接以获取更多信息
我是java新手您可以使用BuffereImage从硬盘加载映像:
BufferedImage img = null;
try {
img = ImageIO.read(new File("strawberry.jpg"));
} catch (IOException e) {
}
请尝试此链接以获取更多信息
这个是用来保存图像的
您可以保存图像
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,不需要第三方库:
byte[] image = /*your image*/
String filePath = /*destination file path*/
File file = new File(filePath);
try (FileOutputStream fosFor = new FileOutputStream(file)) {
fosFor.write(image);
}
听起来你想从磁盘加载一个映像。顺便说一句,您在这里使用的是哪个版本的netbeans-7?通过
JForm
DYMJFrame
使用此链接?J2SE中没有JForm
。
//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//
byte[] image = /*your image*/
String filePath = /*destination file path*/
File file = new File(filePath);
try (FileOutputStream fosFor = new FileOutputStream(file)) {
fosFor.write(image);
}