Meaningless Drivel is fun!*
The moose likes Swing / AWT / SWT and the fly likes Adjustment brightness in an image by slider Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Adjustment brightness in an image by slider" Watch "Adjustment brightness in an image by slider" New topic
Author

Adjustment brightness in an image by slider

Iliqna Ivanova
Greenhorn

Joined: Jun 16, 2012
Posts: 2
Hello,
I have a small program that modify the contrast and brightness in an image. It is implemented by RescaleOp class and modification is performed by sliders - one for the contrast, one for the brightness.
I have a problem with modifying the brightness, it is possible only increasing, not decreasing the color value. Is it my problem because setting the current values or just it not possible to implement it because the rescaleOp class?
Thanks in advance!

Here is the code:

float scaleFactor = 1.1f;
float offset = 5f;

JSlider slider = new JSlider(JSlider.HORIZONTAL, 0, 100, 50); //contrast slider
slider.addChangeListener(new ChangeListener() {

public void stateChanged(ChangeEvent e) {
rescale = new RescaleOp(scaleFactor, offset, null);
JSlider tempSlider = (JSlider) e.getSource();
scaleFactor = (float) (tempSlider.getValue() / 50.0);
textFieldSc.setText(Float.toString(scaleFactor));
imageModified = rescale.filter(imageOriginal, null);
image = imageModified;
canvas.repaint();
}
});

JSlider slider1 = new JSlider(JSlider.HORIZONTAL, 0, 100, 0); //brightness slider
slider1.addChangeListener(new ChangeListener() {

public void stateChanged(ChangeEvent e) {
rescale = new RescaleOp(scaleFactor, offset, null);
JSlider tempSlider1 = (JSlider) e.getSource();
offset = (float) (tempSlider1.getValue());
textFieldSb.setText(Float.toString(offset));
imageModified = rescale.filter(imageOriginal, null);
image = imageModified;
canvas.repaint();
}
});
Piet Souris
Ranch Hand

Joined: Mar 08, 2009
Posts: 650
    
  11
hi Iliqna,

I think it is because offset never gets negative in your stateChanged listener.

offset = (float) (tempSlider1.getValue());


and the slider only permits values from 0 to 100. Perhaps you should distract 50 or so from the value.

But then again, you allways operate on the original image. Should you not also start from the already modified image?

Piet
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Adjustment brightness in an image by slider