java 如何获取label中的图片, 5
FilefileName=newFile("C:\\Users\\Administrator\\Desktop");JFileChooserchooser=newJFil...
File fileName = new File("C:\\Users\\Administrator\\Desktop");
JFileChooser chooser = new JFileChooser(fileName);
FileNameExtensionFilter filter = new FileNameExtensionFilter("JPG & GIF Images", "jpg", "gif");
chooser.setFileFilter(filter);
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
int returnVal = chooser.showOpenDialog(new JPanel());
if(returnVal == JFileChooser.APPROVE_OPTION) {
File fileChooser = chooser.getSelectedFile();
byte[] b = new byte[(int)fileChooser.length()];
try {
InputStream input = new FileInputStream(fileChooser);
input.read(b);
input.close();
}catch(Exception arg1) {
arg1.printStackTrace();
}
addPicture.setIcon(new ImageIcon(b));
我从目录中选择一种图片放进label里面,我在另一个方法中如何获取这张图片 展开
JFileChooser chooser = new JFileChooser(fileName);
FileNameExtensionFilter filter = new FileNameExtensionFilter("JPG & GIF Images", "jpg", "gif");
chooser.setFileFilter(filter);
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
int returnVal = chooser.showOpenDialog(new JPanel());
if(returnVal == JFileChooser.APPROVE_OPTION) {
File fileChooser = chooser.getSelectedFile();
byte[] b = new byte[(int)fileChooser.length()];
try {
InputStream input = new FileInputStream(fileChooser);
input.read(b);
input.close();
}catch(Exception arg1) {
arg1.printStackTrace();
}
addPicture.setIcon(new ImageIcon(b));
我从目录中选择一种图片放进label里面,我在另一个方法中如何获取这张图片 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询