Bonjour,
J'ai fait un petit programme qui permet d'appliquer une roation à une image et d'enregistrer les modifications.
Le code d'enregistrement est:
Le code qui permet d'effectuer la roation est:
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 public static void enregistrerImage(BufferedImage imBuff_,String format_,String nomImage_){ File ficherImage=new File(nomImage_); try { ImageIO.write(imBuff_, format_, ficherImage); } catch (IOException e) { e.printStackTrace(); } }
Lorsque j'afficher direcement l'image dans une JFrame, tout ce passe bien, image bien retournée et même qualité. Mais quand j'enregistre une image retournée sous un format autre que png l'image aparait un peut flou(première photo en fichier attaché).
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
17
18
19
20
21
22
23
24
25
26
27
28
29
30 public static BufferedImage rotate(double angled, BufferedImage image){ double angle=angled*Math.PI*1/180; double sin = Math.abs(Math.sin(angle)), cos = Math.abs(Math.cos(angle)); int w = image.getWidth(), h = image.getHeight(); int neww = (int)Math.floor(w*cos+h*sin), newh = (int)Math.floor(h*cos+w*sin); GraphicsConfiguration gc = getDefaultConfiguration(); BufferedImage result = gc.createCompatibleImage(neww, newh, Transparency.TRANSLUCENT); Graphics2D g = result.createGraphics(); g.translate((neww-w)/2, (newh-h)/2); g.rotate(angle, w/2, h/2); g.drawRenderedImage(image, null); g.dispose(); return result; } public static GraphicsConfiguration getDefaultConfiguration() { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gd = ge.getDefaultScreenDevice(); return gd.getDefaultConfiguration(); } }
D'où pourrait venir le problème?
Merci.
Partager