0

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");
    }
Jamsir Crown
  • 49
  • 2
  • 7
  • [Reading/Loading an Image](http://docs.oracle.com/javase/tutorial/2d/images/loadimage.html) – MadProgrammer Mar 02 '15 at 05:15
  • thank you .. !! I will see and learn .. !! – Jamsir Crown Mar 02 '15 at 05:21
  • you can help me ...? I'm working on the final assignment of invisible watermarking image in java ... !! source code of existing methods and can be run, but the execution was still in the form of an array of input, I will try to execute on the image, but I do not know how to apply the method to the image – Jamsir Crown Mar 02 '15 at 05:52
  • Something like http://stackoverflow.com/questions/6524196/java-get-pixel-array-from-image perhaps? – MadProgrammer Mar 02 '15 at 06:17
  • `chooser.setFileFilter(new FileFilter() {` Use instead `new FileNameExtensionFilter("Image files", ImageIO.getReaderFileSuffixes());` .. and note that the J2SE cannot handle TIFF images short of adding JAI to the run-time class-path. Oh, and please fix that stuck `!` key. One `!` is rarely necessary, while 2 are ***never*** necessary. – Andrew Thompson Mar 02 '15 at 07:11
  • @Andrew Thompson sorry, I just joined this group and I want to learn about it – Jamsir Crown Mar 02 '15 at 08:31

0 Answers0