Hi Randy,
I would not expect TYPE_BILINEAR and TYPE_NEAREST_NEIGHBOR to produce
equally blurry results. Nearest neighbor filtering typically produces
blocky images when scaling because it simply replicates pixels. For
example, if you're scaling by 3x in each dimension, each source pixel is
replicated 3 times in the x and y directions. So a red pixel at (0, 0)
in the source image becomes a red block from (0, 0) to (2, 2) in the new
image. This explains the blockiness I described above.
Bilinear filtering is similar but smoothly interpolates between pixel
values. So if you have a white pixel next to a black pixel in the
source image, in your destination image (assuming the same 3x scale)
your first 4 pixels will probably be (white, light gray, dark gray,
black). This is an over-simplification, but hopefully it makes sense.
You don't need to worry about those other TYPE_* constants in
AffineTransform, they just tell you what "kind" of transform it is. The
code you have below is fine as is. If you just want to make an image
"larger" in the simple sense, then yes, the x and y scale factors should
be the same. It's just like going to a photomat and asking to double
the size of a photo. Each dimension of your new photo will be twice
that of your original (x and y scale factors are 2).
If you're interested in learning more, here are some books you may enjoy:
"Computer Graphics", by Foley, van Dam, et al.
"Java 2D Graphics", by Jonathan Knudsen
"Java 2D API Graphics", by Vincent J. Hardy
Thanks,
Chris
Randy Curnutt wrote:
Thanks, Chris! I actually tried using the TYPE_BILINEAR and it was equally
blurry.
Any ideas on why that might be the case? BTW, I'm using a JPEG file. I
don't know if that could make a difference.
I noticed that their are static constants for TYPE_UNIFORM_SCALE and
TYPE_GENERAL_SCALE etc on the AffineTransform.
Which one of these variables should I use and how do I use it? Are there
any others that are important?
Lastly, if I want an image to scale proportionally then do I use the same
scale factor for the X axis as for the Y axis?
I'm currently using the same scale factor.
Thanks again for any help you can provide!
Regards,
Randy
----- Original Message -----
From: "Chris Campbell" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Wednesday, October 16, 2002 7:49 PM
Subject: Re: [JAVA2D] Question on enlarging an image
Hi Randy,
Your code snippet looks fine, but I'd suggest using
AffineTransformOp.TYPE_BILINEAR rather than TYPE_NEAREST_NEIGHBOR. This
filtering method can be more computationally expensive, but produces
more visually pleasing results. Note that the image will look slightly
blurred, but this is typically more pleasing than a blocky-looking image
(like NEAREST_NEIGHBOR produces).
The approach that Rob mentioned will also get the job done just fine
(getScaledInstance(SCALE_SMOOTH) uses a bilinear filter), but
AffineTransformOp.filter() is more likely to be "natively" accelerated
(in Sun's implementation anyway).
BTW, you can search the java2d-interest archive online at:
http://archives.java.sun.com/java2d-interest.html
Thanks,
Chris
Rob Ratcliff wrote:
Randy,
I've had good luck with this:
Image newImage =
oldImage().getScaledInstance(scaledWidth,scaledHeight,Image.SCALE_SMOOTH));
At 04:49 PM 10/16/2002 -0500, you wrote:
I wasn't able to locate an archive to search so apologize if this is a
duplicate question.
I am using an AffineTransform to make an image larger. Unfortunately
the image is blurred and not sharp or crisp as the original.
I use the same scale both for X and Y. Is that correct?
I'm going to paste the code below.
transform.setToScale(scaleX, scaleY);
AffineTransformOp op = new AffineTransformOp(transform,
AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
Graphics2D biDestG2D = biDest.createGraphics();
biDestG2D.clearRect(0, 0, scaledWidth, scaledHeight);
op.filter(biSrc, biDest);
bufImage = biDest;
Is there a way to enlarge an image and keep the quality of the image?
TIA for any help you can offer. This seems like it should be fairly
straight forward and I just can't get it to work.
Regards,
Randy C.
===========================================================================
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".
--
Chris Campbell 408-276-6429
[EMAIL PROTECTED] x16429
Sun Microsystems, Java 2D USCA22-212
--
Chris Campbell 408-276-6429
[EMAIL PROTECTED] x16429
Sun Microsystems, Java 2D USCA22-212
===========================================================================
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".