I m making App in netbeans platform using java swing Technology.I want to do image processing oncaptured image.This image is capture by X-Ray Gun.after that i want to increase/decrease brightness of image using JSlider.I done this using paintComponent(Graphics g) method. but i want to do direct effect of increased/decreased brightnees of image without using paintComponenet(Graphics g) method.so how can i do that? My code is shown below. In my code i use PlanarImage and BufferedImage class of JAI library for load .tiff imge and after that i use statechange event of JSlider object for increase/decrease brightness of image.
enter code here
import java.awt.BorderLayout;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.awt.image.RescaleOp;
import javax.media.jai.JAI;
import javax.media.jai.PlanarImage;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
public class Main extends JPanel implements ChangeListener {
RescaleOp op;
PlanarImage image = JAI.create("fileload", "F:\\java\\aimages\\teeth1.tiff");
BufferedImage bufferedImage = image.getAsBufferedImage();
BufferedImage bImage;
int x1 = bufferedImage.getWidth();
int y1 = bufferedImage.getHeight();
JSlider slider = new JSlider(-10, 10);
public Main() {
bImage=bufferedImage;
slider.addChangeListener(this);
this.add(slider, BorderLayout.class);
// this.add(new JLabel(new ImageIcon(bufferedImage)), BorderLayout.NORTH);
}
@Override
protected void paintComponent(Graphics g) {
g.drawImage(bufferedImage, 0, 0, x1, y1, null);
}
public static void main(String[] argv) throws Exception {
JFrame jFrame = new JFrame();
jFrame.add(new Main());
jFrame.setVisible(true);
jFrame.setSize(200, 200);
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
@Override
public void stateChanged(ChangeEvent e) {
JSlider slid = (JSlider) e.getSource();
float value = (float) slid.getValue();
setValue(value);
}
private void setValue(float value) {
bufferedImage=bImage;
float scaleFactor = (float) (1.0 + (value / 10.0));
op = new RescaleOp(scaleFactor, 0, null);
bufferedImage = op.filter(bufferedImage, null);
repaint();
}
}
"F:\\java\\aimages\\batman.jpg"
Umm.. that is a JPEG. – Palaeo