餘米使用的Java Swing Technology.I在NetBeans平臺應用使得想要做圖像處理oncaptured image.This圖像是由X射線Gun.after捕捉,我想用JSlider.I做到了這一點,以提高圖像的/降低亮度使用paintComponent(Graphics g)方法。但我想做的直接影響增加/減少圖像brightnees而不使用paintComponenet(Graphics g)method.so我該怎麼做?我的代碼如下所示。在我的代碼中,我使用JAI庫的PlanarImage和BufferedImage類來加載.tiff圖像,之後我使用JSlider對象的statechange事件來增加/減少圖像的亮度。如何在java中使用JSlider增加/減少圖像的亮度?
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();
}
}
* 「爲負載.TIFF IMGE」 * ..' 「F:\\ \\的Java \\ aimages batman.jpg」'嗯..這是** ** JPEG – 2012-04-18 11:40:29
哦~~。對不起,先生,我的錯誤。我更新我的代碼並檢查它。如果你對此有任何想法,請與我分享。 – Jay 2012-04-18 11:56:26
@AndrewThompson請參考這個。 http://stackoverflow.com/questions/10208255/how-to-increase-decrease-brightness-of-image-using-jslider-in-java – Jay 2012-04-18 12:09:45