B
bangsi
Hi,
I'm having trouble resizing PNG images and saving the resized versions
as JPGs, to be displayed as thumbnails in a webapp.
For some PNGs the method I use works fine but for others it doesn't.
Here is what I use:
....
FileSeekableStream fss = new FileSeekableStream(inFile);
RenderedOp image = JAI.create("stream", fss);
....
ParameterBlock params = new ParameterBlock();
params.addSource(image);
params.add(modifier);//x scale factor
params.add(modifier);//y scale factor
params.add(0.0F);//x translate
params.add(0.0F);//y translate
params.add(new InterpolationNearest());
RenderedOp thumb = JAI.create("scale", params);
File outFile = new File("some/filename");
FileOutputStream os = new FileOutputStream(outFile);
ImageIO.write(thumb, "JPEG", os);
os.close();
thumb.dispose();
image.dispose();
fss.close();
....
This works great for converting / resizing other formats to JPGs, like
TIFF, BMP and the same, JPG (didn't have luck with GIFs though, handled
that case separately as GIF -> GIF thumbs, made sense).
Some of the JPG files produced from PNGs by this method don't display
in web browsers but do in other image viewers (though with distorted
colors), some are just zero size and some are just fine.
Any ideas how this can be handled?
/Björn
I'm having trouble resizing PNG images and saving the resized versions
as JPGs, to be displayed as thumbnails in a webapp.
For some PNGs the method I use works fine but for others it doesn't.
Here is what I use:
....
FileSeekableStream fss = new FileSeekableStream(inFile);
RenderedOp image = JAI.create("stream", fss);
....
ParameterBlock params = new ParameterBlock();
params.addSource(image);
params.add(modifier);//x scale factor
params.add(modifier);//y scale factor
params.add(0.0F);//x translate
params.add(0.0F);//y translate
params.add(new InterpolationNearest());
RenderedOp thumb = JAI.create("scale", params);
File outFile = new File("some/filename");
FileOutputStream os = new FileOutputStream(outFile);
ImageIO.write(thumb, "JPEG", os);
os.close();
thumb.dispose();
image.dispose();
fss.close();
....
This works great for converting / resizing other formats to JPGs, like
TIFF, BMP and the same, JPG (didn't have luck with GIFs though, handled
that case separately as GIF -> GIF thumbs, made sense).
Some of the JPG files produced from PNGs by this method don't display
in web browsers but do in other image viewers (though with distorted
colors), some are just zero size and some are just fine.
Any ideas how this can be handled?
/Björn