Bonjour, je voudrais savoir comment modifier ma methode public void paint(Graphics g) afin que mon image conserve les proportions initiales meme si la fenetre est redimensionnée?
voici mon code actuel:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 BufferedImage img; public void paint(Graphics g) { if (img == null) return; //CONSERVER LES DIMENSIONS DE L'IMAGE int x = getWidth();; int y = getHeight(); final double proportion1 = getWidth()/getHeight(); final double proportion2 = getHeight()/getWidth(); if(x/y != proportion1) {x= (int) (y*proportion1);repaint();} else if(y/x != proportion2) {y = (int) (x*proportion2);repaint();} g.drawImage(img, 0, 0, x, y, this); }
Partager