problem using JAI bilinear interpolation to scale a bufferedimage

Discussion in 'Java' started by Raj, Nov 25, 2003.

  1. Raj

    Raj Guest

    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;
    }
    Raj, Nov 25, 2003
    #1
    1. Advertising

  2. Please do not multi-post, Raj, it is worse
    than cross-posting.

    "Raj" <> wrote in message
    news:...
    ...
    > I am trying to write a function which rescales a bufferedimage using
    > JAI biliner interpolation
    Andrew Thompson, Nov 25, 2003
    #2
    1. Advertising

  3. Raj

    ak Guest

    better you ask JAI-interest group -
    http://swjscmail1.sun.com/archives/jai-interest.html


    "Raj" <> schrieb im Newsbeitrag
    news:...
    > 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;
    > }
    ak, Nov 25, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. atusc
    Replies:
    1
    Views:
    4,186
  2. news.skynet.be
    Replies:
    0
    Views:
    563
    news.skynet.be
    Mar 25, 2005
  3. Replies:
    5
    Views:
    849
  4. harryos
    Replies:
    0
    Views:
    577
    harryos
    Jul 19, 2008
  5. Dangling Pointer
    Replies:
    8
    Views:
    944
    Roedy Green
    May 21, 2012
Loading...

Share This Page