title: How to Change Brightness of Image?
body: <p>i have made an application that loads image from specific directory, loads all images in stack, when i am clicking on next button next image loads.
  i have also added JSlider that change Brightness of Loaded Image but it doesn't work.
  i don't know why but i am not getting exact problem.</p>
  
  <p>my code :</p>
  
  <pre class="lang-java prettyprint-override"><code>public class PictureEditor extends JFrame 
  { 
      private static final long serialVersionUID = 6676383931562999417L; 
  
      String[] validpicturetypes = {"png", "jpg", "jpeg", "gif"}; 
      Stack&lt;File&gt; pictures ;
      JLabel label = new JLabel(); 
      BufferedImage a = null; 
      float fval=1;
  
      public PictureEditor() 
      { 
          JPanel panel = new JPanel(); 
          JMenuBar menubar = new JMenuBar(); 
          JMenu toolsmenu = new JMenu("Tools"); 
  
  
          final JSlider slider1;
              slider1 = new JSlider(JSlider.HORIZONTAL,0,4,1);
              slider1.setToolTipText("Slide To Change Brightness");
              slider1.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null));
              slider1.setMajorTickSpacing(1);
              slider1.setPaintLabels(true);
              slider1.setPaintTicks(true);
              slider1.setPaintTrack(true);
              slider1.setAutoscrolls(true);
              slider1.setBounds(50, 55, 200, 50);
  
              slider1.addChangeListener(new ChangeListener() 
              {
  
                  @Override
                  public void stateChanged(ChangeEvent e) 
                  {
                      System.out.println("Before");
                      fval=slider1.getValue();
                      chgBrt(fval);
                      repaint();
                  }
              });
  
          TitledBorder title;
          title = BorderFactory.createTitledBorder("Operations");
          title.setTitleJustification(TitledBorder.LEFT);
  
          JButton RT90 = new JButton("");
          JButton RT180 = new JButton("");
          JButton RTM90 = new JButton("");
          JButton RTM180 = new JButton("");
          JButton NEXT = new JButton("");
          Image img = null;
          Image imgn = null;
  
          try 
          {
              img = ImageIO.read(getClass().getResource("/images/images_Horizontal.png"));
              imgn = ImageIO.read(getClass().getResource("/images/next12.png"));
          }
          catch (IOException e) 
          {
              e.printStackTrace();
          }
          RT90.setIcon(new ImageIcon(img));
          RT180.setIcon(new ImageIcon(img));
          RTM90.setIcon(new ImageIcon(img));
          RTM180.setIcon(new ImageIcon(img));
          NEXT.setIcon(new ImageIcon(imgn));
  
          JPanel buttonPane = new JPanel();
  
          buttonPane.add(slider1);
  
          buttonPane.add(Box.createRigidArea(new Dimension(250,0)));
  
          buttonPane.setBorder(title);
          buttonPane.add(RT90);
          buttonPane.add(RT180);
          buttonPane.add(RTM90);
          buttonPane.add(RTM180);
  
  
          buttonPane.add(Box.createRigidArea(new Dimension(250,0)));
  
  
          NEXT.addActionListener(new ActionListener() {
  
              @Override
              public void actionPerformed(ActionEvent arg0) 
              {           
                  nextImage();
              }
          });
          buttonPane.add(NEXT);
          getContentPane().add(buttonPane, BorderLayout.SOUTH);
  
          final File dir = new File("");
          final JFileChooser file;
          file = new JFileChooser();
          file.setCurrentDirectory(dir);
          file.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
          file.showOpenDialog(panel);
          String path = file.getSelectedFile().getAbsolutePath();
          System.out.println(path);
          pictures= getFilesInFolder(path.toString()); 
  
          Action nextpictureaction = new AbstractAction("Next Picture") 
          { 
              private static final long serialVersionUID = 2421742449531785343L; 
  
              @Override 
              public void actionPerformed(ActionEvent e) 
              {   
                  nextImage();    
              }
  
          }; 
          setJMenuBar(menubar); 
          menubar.add(toolsmenu); 
          toolsmenu.add(nextpictureaction); 
  
          panel.add(label,BorderLayout.CENTER); 
          add(panel);     
  
          setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
          setLocationByPlatform(true); 
          setSize(1000, 700); 
          setTitle("PictureEditor"); 
          setVisible(true); 
      } 
  
      public Stack&lt;File&gt; getFilesInFolder(String startPath) 
      { 
          File startFolder = new File(startPath); 
          Stack&lt;File&gt; picturestack = new Stack&lt;File&gt;(); 
  
          String extension; 
          int dotindex; 
  
          // Go through the folder 
          for (File file : startFolder.listFiles()) 
          { 
              extension = ""; 
              dotindex = file.getName().lastIndexOf('.'); // Get the index of the dot in the filename 
  
              if (dotindex &gt; 0) 
              { 
                  extension = file.getName().substring(dotindex + 1);             
                  // Iterate all valid file types and check it 
                  for (String filetype : validpicturetypes) 
                  { 
                      if (extension.equals(filetype))
                      { 
                          picturestack.add(file); 
                      } 
                  } 
              } 
          } 
      return picturestack; 
      } 
  
      public void nextImage()
      {       
  
          try 
          {
              a=ImageIO.read(pictures.pop().getAbsoluteFile());       
          } 
          catch (IOException e1) 
          {
              e1.printStackTrace();
          }
          final ImageIcon image = new ImageIcon(a);
  
          label.setIcon(image);
          repaint();
      }
      @SuppressWarnings("null")
      public void chgBrt(float f)
      {
            Graphics g = null;
            Graphics2D g2d=(Graphics2D)g;
            try
            {  
                BufferedImage dest=changeBrightness(a,(float)fval);          
                System.out.println("Change Bright");
  
                int w = a.getWidth();
                int h = a.getHeight();              
                g2d.drawImage(dest,w,h,this);      
  
                ImageIO.write(dest,"jpeg",new File("/images/dest.jpg"));
                System.out.println("Image Write");
            }
            catch(Exception e)
            {
                  e.printStackTrace();
            }
      }
  
      public BufferedImage changeBrightness(BufferedImage src,float val)
      {
           RescaleOp brighterOp = new RescaleOp(val, 0, null);
           return brighterOp.filter(src,null); //filtering
      }
  
      public static void main(String[] args) 
      { 
          javax.swing.SwingUtilities.invokeLater(new Runnable() 
          { 
              public void run() 
              { 
                  new PictureEditor(); 
              } 
          }); 
      } 
  }
  </code></pre>
  
  <p><strong>anyone who can guide me and tell me where i am wrong ??</strong></p>