By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,779 Members | 1,101 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,779 IT Pros & Developers. It's quick & easy.

createScaledRendering weird problem when create small thumbnail

P: n/a
I have following code to convert a big image to smaller thumbnail,
it work's fine until one day this image come out

http://www.here4now.com/mobdata/sunb...Untitled-2.gif

The original size is 200x205, if I resize it to 101x103, it looks
still fine, but one pixed smaller , say 100x102, the result image is
total unacceptable.

Any help or hint will be appreciate
Ivan Wang

P.S. I didn't use Image.getScaledInstance to resize the image because
our server don't have X-window installed.

/************************************************** *****************/
public static void resize(String file1, String file2){
source = JAI.create("fileload", file1);
ParameterBlock pb = new ParameterBlock();
pb.addSource(source);
pb.add(null).add(null).add(null).add(null).add(nul l);
RenderableImage ren = JAI.createRenderable("renderable", pb);
pb = new ParameterBlock();
pb.addSource(ren);
int w = source.getWidth()/2;
int h = source.getHeight()/2;
//RenderingHints renderingHints = new RenderingHints( null );
//renderingHints.put( RenderingHints.KEY_COLOR_RENDERING,
// RenderingHints.VALUE_COLOR_RENDER_QUALITY );
PlanarImage dst = (PlanarImage)ren.createScaledRendering(w, h,
null);
JAI.create("filestore",dst,file2,"PNG");
}
/************************************************** *****************/
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On 28 Jun 2004 07:44:53 -0700, xj******@yahoo.com
(xj******@hotmail.com) wrote or quoted :
The original size is 200x205, if I resize it to 101x103, it looks
still fine, but one pixed smaller , say 100x102, the result image is
total unacceptable.

Any help or hint will be appreciate


Gifs only look decent resized when you scale them by powers of two.
If you want something that scales well, use JPEG.

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
Jul 17 '05 #2

P: n/a
xj******@yahoo.com (xj******@hotmail.com) wrote in message news:<a9**************************@posting.google. com>...
I have following code to convert a big image to smaller thumbnail,
it work's fine until one day this image come out

http://www.here4now.com/mobdata/sunb...Untitled-2.gif

The original size is 200x205, if I resize it to 101x103, it looks
still fine, but one pixed smaller , say 100x102, the result image is
total unacceptable.

Any help or hint will be appreciate
Ivan Wang

P.S. I didn't use Image.getScaledInstance to resize the image because
our server don't have X-window installed.

/************************************************** *****************/
public static void resize(String file1, String file2){
source = JAI.create("fileload", file1);
ParameterBlock pb = new ParameterBlock();
pb.addSource(source);
pb.add(null).add(null).add(null).add(null).add(nul l);
RenderableImage ren = JAI.createRenderable("renderable", pb);
pb = new ParameterBlock();
pb.addSource(ren);
int w = source.getWidth()/2;
int h = source.getHeight()/2;
//RenderingHints renderingHints = new RenderingHints( null );
//renderingHints.put( RenderingHints.KEY_COLOR_RENDERING,
// RenderingHints.VALUE_COLOR_RENDER_QUALITY );
PlanarImage dst = (PlanarImage)ren.createScaledRendering(w, h,
null);
JAI.create("filestore",dst,file2,"PNG");
}
/************************************************** *****************/


Here is my new code, the scaled picture looks alright this time

public static void resize(String file1, String file2){
source = JAI.create("fileload", file1);
ParameterBlock pb = new ParameterBlock();
pb.addSource(source);
pb.add(null).add(null).add(null).add(null).add(nul l);
RenderableImage ren = JAI.createRenderable("renderable", pb);

int h = source.getHeight();
int w = source.getWidth();
PlanarImage dst = (PlanarImage)ren.createScaledRendering(w, h, null);

pb = new ParameterBlock();
pb.addSource(dst);
pb.add(0.3f); // 0.3 is just some test data
pb.add(0.3f);
pb.add(0.0f);
pb.add(0.0f);
pb.add(new InterpolationNearest()); // <-- this is the key
PlanarImage transformedImage = JAI.create("scale", pb, null);
JAI.create("filestore",transformedImage,file2,"PNG ");
}
================================================== =========
I have to use JAI.create("scale",pb,hints)
rather than createScaledRendering(w, h, hints) to make it working.
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.