OVH Cloud OVH Cloud

[imaging] comment réduire une image correctement ?

1 réponse
Avatar
zebulon
Je veux réduire la taille d'images en java. Avec ce code (JAI), la qualité
de l'image réduite n'a rien de comparable avec ce que l'on obtiendrait avec
PhotoShop.
Comment faire mieux ?
merci

//LOAD
InputStream is = new FileInputStream(inputpath);
SeekableStream s = SeekableStream.wrapInputStream(is, true);
RenderedOp objImage = JAI.create("stream", s);

//REDUIT
float xScale = destwidth/objImage.getWidth();

ParameterBlock pb = new ParameterBlock();
pb.addSource(objImage); // The source image
pb.add(xScale); // The xScale
pb.add(xScale); // The yScale
pb.add(0.0F); // The x translation
pb.add(0.0F); // The y translation
// pb.add(new InterpolationNearest()); // The interpolation
pb.add(new InterpolationBicubic(8)); // The interpolation
// pb.add(new InterpolationBilinear()); // The interpolation

objImage = JAI.create("scale", pb, null);


//FLUSH OUT
FileOutputStream os = new FileOutputStream(outputpath);
//JAI.create("encode", objImage, os, type, null);
JAI.create("encode", objImage, os, null, null);

1 réponse

Avatar
Anthony Goubard
Salut,

Je te conseille de ne pas utiliser JAI et d'utiliser
Image.getScaledInstance() avec l'option Image.SCALE_SMOOTH

Anthony

zebulon wrote:
Je veux réduire la taille d'images en java. Avec ce code (JAI), la qualité
de l'image réduite n'a rien de comparable avec ce que l'on obtiendrait avec
PhotoShop.
Comment faire mieux ?
merci

//LOAD
InputStream is = new FileInputStream(inputpath);
SeekableStream s = SeekableStream.wrapInputStream(is, true);
RenderedOp objImage = JAI.create("stream", s);

//REDUIT
float xScale = destwidth/objImage.getWidth();

ParameterBlock pb = new ParameterBlock();
pb.addSource(objImage); // The source image
pb.add(xScale); // The xScale
pb.add(xScale); // The yScale
pb.add(0.0F); // The x translation
pb.add(0.0F); // The y translation
// pb.add(new InterpolationNearest()); // The interpolation
pb.add(new InterpolationBicubic(8)); // The interpolation
// pb.add(new InterpolationBilinear()); // The interpolation

objImage = JAI.create("scale", pb, null);


//FLUSH OUT
FileOutputStream os = new FileOutputStream(outputpath);
//JAI.create("encode", objImage, os, type, null);
JAI.create("encode", objImage, os, null, null);