Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Adjustment brightness in an image by slider

 
Iliqna Ivanova
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 1370
29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic