problem using JAI bilinear interpolation to scale a bufferedimage

R

Raj

Hi ,
I am trying to write a function which rescales a bufferedimage using
JAI biliner interpolation

But it seems the rescaled image looses the data and now only a part of
the rescaled image is visible.I read the JAI documentation and read
somewhere that its because of not giving the proper renderinghint to
extend the border.
So i created the renderinghint and added it to the the JAI.create
method,still the result is same.

What am i doing wrong???I am new to this and am totally flabbergasted
:(
Help me!!!

Copying the code below

Thanx a lot
Raj


public static BufferedImage _rescale(BufferedImage image, float
xScale,
float yScale)
{
if((xScale == 1.0f)&& (yScale == 1.0f)){return image;}
// Interpolation interp = Interpolation.getInstance(
// Interpolation.INTERP_BICUBIC);
Interpolation interp =
Interpolation.getInstance(Interpolation.INTERP_BILINEAR);
ParameterBlock params = new ParameterBlock();
params.addSource(image);
params.add(xScale);
params.add(yScale);

/** Add x translate */
params.add(0.0F);

/** Add y translate */
params.add(0.0F);

/** Adds interpolation method */
params.add(interp);


RenderingHints rh = new RenderingHints(JAI.KEY_BORDER_EXTENDER,
BorderExtender.createInstance(BorderExtender.BORDER_COPY));





RenderedOp outputImage = JAI.create("scale", params,rh);
//RenderedOp outputImage = JAI.create("scale", params);
Raster raster = outputImage.getData();
//BufferedImage result=new BufferedImage();
BufferedImage result = new BufferedImage(raster.getWidth(),
raster.getHeight(),
IMAGE_TYPE);

System.out.println(raster.getWidth()+"---"+
raster.getHeight());
result.setData(raster);
return result;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top