Posts

Showing posts from June, 2008

Generating thumbnail images: AffineTransformOp gotchas

AffineTransformOp is a Java 2D filter that can scale (resize), rotate, and/or skew an image. Since I was generating thumbnails, I was only interested in its scaling ability. To scale an image using AffineTransformOp, all you need to do is generate a new AffineTransform using the static method AffineTransform.getScaleInstance, then use it to construct an AffineTransformOp. When constructing an AffineTransformOp, you also need to pass a constant theat identifies the type of interpolation to use, either nearest neighbor, bilinear, or bicubic. Once you have the AffineTransformOp, you just call the filter method, passing in the original image and the destination image, which can be null, in which case AffineTransformOp will create a destination image for you. After generating my first thumbnail image and saving it as a JPEG, I was able to view my generated thumbnail image in Preview, but it looked like crap. It looked blocky, as if AffineTransformOp was using the nearest neighbor interp

Java 2D image-processing gotchas

I've been working with Java 2D a fair bit over the past few weeks and encountered a fair number of gotchas, or least behavior that seemed strange to me at first but that eventually made sense, once I thought about it and/or UTSL and figured out why it was working that way. By way of background, I've mostly been developing web applications for the past eight years, so my experience with Java 2D is minimal. I've been investigating the image-processing capabilities of Java 2D because I need to implement a new feature for my photography web site, photoSIG . The feature will blur thumbnail images of photos on the photo-browsing pages if the "content rating" of those photos is either R or X, and the page is displaying advertising. The purpose of this new feature is to recover some advertising inventory that I currently can't use because advertisers don't want their ads appearing on the same page as R or X photos, even if they're thumbnails. At various poi