> 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??
Generally, when you perform an operation requiring interpolation (such as convolution or scaling with interpolated resampling) on an image with an alpha channel, you should use a color model with premultiplied alpha. An example of why this is true is given in the paper "Compositing, Part 1: Theory" by Jim Blinn from IEEE Computer Graphics and Applications, September 1994 (reprinted in Blinn's book Jim Blinn's Corner: Dirty Pixels). If you change the BufferedImage type to TYPE_INT_ARGB_PRE in the sample program, there will be no gray border. Without the premultiplication, at the border between 255/255/255/0 pixels and 255/255/255/255 pixels in the scaled up image, there are pixels which are the result of resampling with input from both types of pixels from the unscaled image. Resampling a non-premultiplied image effectively treats the RGB samples as completely independent of the alpha samples for interpolation. The Blinn paper illustrates why this doesn't give the desired result. Jerry =========================================================================== 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".
