1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
private JLabel lImage;
private JPanel pImage;
private BufferedImage image;
private double coef = 1;
public void mouseWheelMoved(MouseWheelEvent e) {
int rot = e.getWheelRotation();
LogFile.addMessage("mouseWheelMoved : rot=" + rot);
if (rot > 0)
coef = coef * 0.5;
else
coef = coef * 2;
pImage.removeAll();
Image img = zoom(image, coef);
lImage = new JLabel(new ImageIcon(Toolkit.getDefaultToolkit().createImage(img.getSource())));
//pImage.add(new JLabel(new ImageIcon(img)), BorderLayout.CENTER);
pImage.add(lImage, BorderLayout.CENTER);
pImage.revalidate();
}
private BufferedImage zoom(BufferedImage bi, double zoomValue){
// Test des parametre :
if (bi == null) return null;
//if (zoomValue > 0 && zoomValue != (int)zoomValue)return null;
BufferedImage biNew = new BufferedImage( (int) (bi.getWidth() * zoomValue),
(int) (bi.getHeight() * zoomValue),
bi.getType());
for (int it = 0 ; it < biNew.getWidth(); it++){
for (int jt = 0 ; jt < biNew.getHeight(); jt++){
biNew.setRGB(it, jt, bi.getRGB((int)(it / zoomValue), (int)(jt / zoomValue) ));
}
}
return biNew;
} |
Partager