Salut je fais un site ou j'upload des photos, puis je crées 2 miniature (1 largeur fixe et une hauteur fixe), ça marche impec avec les png et gif, mais les jpg ne passe pas, sans avoir d'erreur le fichier redimensionné jpg pèse 0k et si je l'ouvre avec spot ça met :
Erreur d'interprétation du fichier d'image JPEG (Improper call to JPEG library in state 200)
Voici mes sources :
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
                              try {
                                    Img img=new Img();
                                    img.getSize(file);
                                    String fileNameMini1=Datas.uploadDir+"photos/mini1_"+idPhoto+extension;
                                    String fileNameMini2=Datas.uploadDir+"photos/mini2_"+idPhoto+extension;
                                    File fileMini1=new File(fileNameMini1);
                                    File fileMini2=new File(fileNameMini2);
                                    img.resizeWidth(file, fileMini1, Datas.MINIAT1WIDTH);
                                    img.resizeHeight(file, fileMini2, Datas.MINIAT2HEIGHT);
                                    if(img.width>Datas.MAXWIDTHPHOTOS)
                                        img.resizeWidth(file, file, Datas.MAXWIDTHPHOTOS);
                                    img.getSize(file);
                                    if(img.height>Datas.MAXHEIGHTPHOTOS)
                                        img.resizeHeight(file, file, Datas.MAXHEIGHTPHOTOS);
                        } catch (Exception ex) {
                            Logger.getLogger(MembrePhotos.class.getName()).log(Level.SEVERE, null, ex);
                            //int i=1/0;
                                query="DELETE FROM table_photos WHERE id=?";
                                prepare=getConnect().prepareStatement(query);
                                prepare.setInt(1, idPhoto);
                                prepare.executeUpdate();
                                this.setErrorMsg(textes.inscErr23);
                        }
et ma classe Img :

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
83
84
package classes;
 
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
 
/**
 *
 * @author pj
 */
public class Img {
    BufferedImage source;
    BufferedImage destination;
    File sourceFile;
    File destinationFile;
    int width;
    int height;
    String extension;
 
    public boolean resizeWidth(File sourceFile, File destinationFile, int width) {
        try {
            this.sourceFile = sourceFile;
            this.destinationFile=destinationFile;
            this.extension=(sourceFile.getName().substring(sourceFile.getName().lastIndexOf("."))).toLowerCase();
            this.extension=this.extension.substring(1);
            this.source = ImageIO.read(this.sourceFile);
            this.width = width;
            int height0 = this.source.getHeight();
            int width0 = this.source.getWidth();
            this.height = (int) (((double)height0*(double)this.width)/((double)width0));
            this.destination = new BufferedImage(this.width, this.height, BufferedImage.TYPE_INT_ARGB);
            Graphics2D g = this.destination.createGraphics();
            g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
            g.drawImage(this.source, 0, 0, this.width, this.height, null);
            g.dispose();
            ImageIO.write(this.destination, this.extension, this.destinationFile);
            return true;
        } catch (IOException ex) {
            Logger.getLogger(Img.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
   }
    public boolean resizeHeight(File sourceFile, File destinationFile, int height) {
        try {
            this.sourceFile = sourceFile;
            this.destinationFile=destinationFile;
            this.extension=(sourceFile.getName().substring(sourceFile.getName().lastIndexOf("."))).toLowerCase();
            this.extension=this.extension.substring(1);
            this.source = ImageIO.read(this.sourceFile);
            this.height = height;
            int height0 = this.source.getHeight();
            int width0 = this.source.getWidth();
            this.width = (int) (((double)width0*(double)this.height)/((double)height0));
            this.destination = new BufferedImage(this.width, this.height, BufferedImage.TYPE_INT_ARGB);
            Graphics2D g = this.destination.createGraphics();
            g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
            g.drawImage(this.source, 0, 0, this.width, this.height, null);
            g.dispose();
            ImageIO.write(this.destination, this.extension, this.destinationFile);
            return true;
        } catch (IOException ex) {
            Logger.getLogger(Img.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
   }
   public boolean getSize(File sourceFile) {
        try {
            this.sourceFile = sourceFile;
            this.source = ImageIO.read(this.sourceFile);
            this.width=this.source.getWidth();
            this.height=this.source.getHeight();
            return true;
        } catch (IOException ex) {
            Logger.getLogger(Img.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
 
   }
}
merci pour votre aide !