Bonjour,

J'ai un programme qui lit une image jpeg, qui la redimensionne et qui sauvegarde l'image redimensionner.

Le gros problème que je rencontre est la perte de qualité énorme entre l'image originale et l'image retaillée.

Je vous laisse le code que j'uilise pour effetuer le redimensionnement :

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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
 
import java.awt.geom.AffineTransform;
import java.awt.image.*;
import java.io.*;
import javax.imageio.ImageIO;
import java.awt.*;
import javax.swing.*;
import javax.media.jai.*;
import java.awt.image.renderable.ParameterBlock;
 
public class Jpeg
{
    public Jpeg()
    {
    }
 
    // i  = la largeur de l'image redimensionner
    // s  = le chemin d'acces à l'image original
    // s1 = le chemin d'acces à l'image retaillée
    public boolean resize(int i, String s, String s1)
    {
       try
        {
            File file  = new File(s);
            File file1 = new File(s1);
 
            //Parametrage de la lecture
            ImageIO.setUseCache (true);
 
            BufferedImage src = ImageIO.read(file);
 
            double d  = src.getWidth();
            double d1 = src.getHeight();
            double d2 = i;
            double d3 = d2 / d;
 
            if(d1 * d3 > d2)
            {
                d3 = d2 / d1;
            }
 
            if(d3 > 0.8D)
            {
                d3 = 1.0D;
            }
 
            int j = (int)(d * d3);
            int k = (int)(d1 * d3);
 
	    AffineTransform  tx = new AffineTransform ();
            tx.scale (d3, d3);
 
            RenderingHints  rh = new RenderingHints (RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            rh.put (RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
            rh.put (RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
            rh.put (RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
            rh.put (RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
            rh.put (RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
            rh.put (RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
 
            AffineTransformOp  op    = new AffineTransformOp (tx, rh);
            BufferedImage      biNew = new BufferedImage (j, k, src.getType ());
 
            op.filter(src, biNew);
 
            ImageIO.write (biNew, "jpg", new File (s1));
        }
        catch (Exception  e)
        {
            e.printStackTrace ();
            return  false;
        }
 
        return  true;
    }
 
    public static void main(String args[])
    {
        Jpeg jpeg = new Jpeg();
        jpeg.resize (Integer.parseInt (args [0]), args[1], args[2]);
    }
}
De plus je vous laisse les liens vers les images :

image originale : http://193.252.12.20/bugimage/14457.jpg
image retaillée par le programme : http://193.252.12.20/bugimage/bur.jpg
image retaillée par paint shop pro : http://193.252.12.20/bugimage/psp.jpg

Merci de votre aide.