This is a JFileChooser
source code. I want an image that is opened using this file chooser can be read, so that it can take RGB pixel values in the image and can be processed to the next stage. But I do not know what I should do, I just learned about this, there may be a need to add to this source code...!!!
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch (Exception ex)
{
}
JFileChooser chooser = new JFileChooser(System.getProperty("user.home") + System.getProperty("file.separator")+ "Pictures");
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
chooser.setAcceptAllFileFilterUsed(false);
chooser.setDialogTitle("Choose a photo");
chooser.setApproveButtonText("Buka Gambar");
chooser.setFileFilter(new FileFilter() {
@Override
public String getDescription() {
return "Semua Format Gambar";
}
@Override
public boolean accept(File f) {
if (f.isDirectory()) {
return true;
} else {
return f.getName().toLowerCase().endsWith(".jpg")
|| f.getName().toLowerCase().endsWith(".gif")
|| f.getName().toLowerCase().endsWith(".png")
|| f.getName().toLowerCase().endsWith(".bmp")
|| f.getName().toLowerCase().endsWith(".jpeg")
|| f.getName().toLowerCase().endsWith(".tiff");
}
}
});
int res = chooser.showOpenDialog(MSE_PSNR.this);
try {
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
} catch (Exception ex) {
ex.printStackTrace();
}
if (res == JFileChooser.APPROVE_OPTION) {
File file = chooser.getSelectedFile();
String path = chooser.getSelectedFile().toString();
jTextField1.setText(path);
ImageIcon image = new ImageIcon(file.getAbsolutePath());
Rectangle rect = jLabel5.getBounds();
Image scaledImage = image.getImage();
image = new ImageIcon(scaledImage);
jLabel5.setIcon(image);
} else
{
JOptionPane.showMessageDialog(this, "Batal Memilih Gambar");
}