Hello,

This is a baffling problem first reported by Hitoshi Sato of IBM-Japan
some 2-3 weeks ago on this mailing list. It seems like there is a
problem using bilinear interpolation on a Buffered Image under some
special circumstances. The circumstances are  ...

1) The BufferedImage is a TYPE_INT_ARGB
2) A rectangle is filled with a completely transparent color (say white,
although it behaves the same with any color)
3) A smaller rectangle is filled over the top of it using a completely
opaque color (also white)
4) The  BufferedImage is then scaled by a factor of 2.0 with Bilinear
interpolation using an AffineTransformOp.
5) The resulting BufferedImage is then drawn in a JFrame with a white
background.

The result is a gray border around the form of the smaller rectangle.

If the alpha of the outer rectangle is changed to be even 1, the effect
goes away. Does any have a clue as to why this should be the behavior??

Hitoshi's code is found below.

package test;

/**
 * Interpolation test code.
 *  visualizer edition
 */
import java.awt.*;
import java.awt.geom.*;
import java.awt.image.*;
import java.awt.event.*;
import javax.swing.*;
public class VInterpolationTest extends JFrame {
        BufferedImage bi;
/**
 */
VInterpolationTest(BufferedImage bi) {
        this.bi = bi;
}
/**
 */
public static void main(String[] args) {
        BufferedImage src = createTestImage(200, 200);
        BufferedImage result = resize(src, 2.0, 2.0,
                        AffineTransformOp.TYPE_BILINEAR);
        VInterpolationTest test = new VInterpolationTest(result);
        test.addWindowListener(new WindowAdapter() {
                public void windowClosing(WindowEvent e)
{System.exit(0);}
        });
        test.setSize(600, 500);
        test.show();
}
/**
 */
public void paint(Graphics g) {
        Graphics2D g2 = (Graphics2D)g;
        g2.setColor(new Color(255,255,255,255));
        g2.fillRect(0, 0, getWidth(), getHeight());
        g2.drawImage(this.bi, null, 0, 0);
}
/**
 */
static BufferedImage createTestImage(int width, int height) {
        BufferedImage bi = new BufferedImage(width, height,
                                BufferedImage.TYPE_INT_ARGB);
        Graphics2D g2 = bi.createGraphics();

        Color outer = new Color(255, 255, 255, 0);
        Color inner = new Color(255, 255, 255, 255);

        g2.setColor(outer);
        g2.fillRect(0, 0, width, height);

        g2.setColor(inner);
        g2.fillRect(width/4, height/4, width/2, height/2);

        return bi;
}
/**
 */
static BufferedImage resize(BufferedImage bi,
                double scaleX, double scaleY, int interpolation) {
        AffineTransform at =
                        AffineTransform.getScaleInstance(scaleX,
scaleY);
        AffineTransformOp ato =
                        new AffineTransformOp(at, interpolation);
        return ato.filter(bi, null);
}
}

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to