> Any guesses as to what I should be looking for in my code. Note, the
> image is getting passed around and copied during the operation. It isn't
[quoted text clipped - 6 lines]
>
> Thanks for any help you can provide with this poor problem description.

Signature
Knute Johnson
email s/nospam/linux/
> What is it supposed to anti-alias with if it is clear?
I can show you what I'm expecting since that's what my SSCE is doing:
import java.awt.AlphaComposite;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JComponent;
import javax.swing.JFrame;
public class Example extends JComponent {
BufferedImage image;
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {
JFrame frame = new JFrame("Example");
frame.setBounds(new Rectangle(0, 0, 200, 200));
Example example = new Example(new File(args[0]));
frame.add(example);
frame.setVisible(true);
}
public Example(File imageFile) throws IOException {
BufferedImage imageTemp = ImageIO.read(imageFile);
// We need to make sure it has transparency
image = new BufferedImage(imageTemp.getWidth(),
imageTemp.getHeight(),
BufferedImage.TYPE_4BYTE_ABGR);
Graphics2D graphics = image.createGraphics();
graphics.drawImage(imageTemp, 0, 0, image.getWidth(),
image.getHeight(), null);
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
graphics.setStroke(new BasicStroke(16, BasicStroke.CAP_ROUND,
BasicStroke.JOIN_ROUND));
graphics.setColor(Color.BLACK);
graphics.drawLine(0, 50, image.getWidth(), 60);
graphics.setComposite(AlphaComposite.getInstance
(AlphaComposite.CLEAR));
graphics.drawLine(0, 100, image.getWidth(), 120);
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D graphics = (Graphics2D) g;
graphics.drawImage(image, 0, 0, getWidth(), getHeight(), null);
}
}
OK, if you run this and pass in an image on the command line, then you
will see that image drawn with two lines through it, both anti-aliased.
The top one is black and the bottom one is completely transparent. If
you look at it you'll see that the bottom line has pixels where the
transparency isn't just set to 0. Some of the pixels might have a
transparency of 0.25 or some such. So the transparent line blends with
whatever the background is to make a line that is anti-aliased.
This is what I'm expecting. Unfortunately the code I'm working with
doesn't do that.
I found the minimum change I need to make to demonstrate the problem, but
I can't simplify it or everything works. Unfortunately I can't see
anyway to really simplify the code I'm working with. It looks identical
to the above code. I'm not sure what's going on.
I just had a guess occur to me. Maybe at some point the image is being
copied to a BufferedImage with only BIT_MASK transparency. Would that
result in the behavior I've described? That is no anti-aliasing in the
transparent region, but perfect anti-aliasing outside it?
Anyway, the only method I'm changing to demonstrate the difference is
this:
private void drawLine(Graphics2D graphics, int x1, int y1, int x2,
int y2,
boolean clear, Color color) {
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
x1 -= getXPosition();
x2 -= getXPosition();
y1 -= getYPosition();
y2 -= getYPosition();
x1 *= 1.0/getScaleFactor();
y1 *= 1.0/getScaleFactor();
x2 *= 1.0/getScaleFactor();
y2 *= 1.0/getScaleFactor();
graphics.setStroke(new BasicStroke(eraserSize,
BasicStroke.CAP_ROUND,
BasicStroke.JOIN_ROUND));
logger.finest("Drawing line: "
+ x1 + ", " + y1 + ", " + x2 + ", " + y2);
if (clear) {
graphics.setComposite(AlphaComposite.getInstance
(AlphaComposite.CLEAR));
} else if (color != null) {
graphics.setColor(color);
}
graphics.drawLine(x1, y1, x2, y2);
graphics.dispose();
}
If I call this method with a non-null Color and false in the argument,
clear, then I get an anti-aliased line (as long as it doesn't intersect a
completely transparent portion of the image).
If I call this method with a true in the argument, clear, then I get a
line that is not anti-aliased.

Signature
Kenneth P. Turvey <kt-usenet@squeakydolphin.com>
Kenneth P. Turvey - 17 May 2008 01:58 GMT
On Sat, 17 May 2008 00:43:42 +0000, I wrote:
> I just had a guess occur to me. Maybe at some point the image is being
> copied to a BufferedImage with only BIT_MASK transparency. Would that
> result in the behavior I've described? That is no anti-aliasing in the
> transparent region, but perfect anti-aliasing outside it?
Problem solved. This was it. I did a search through the code for
Tranparency and found a Transparency.BITMASK in a super class. So when I
called this code, the transparency was flattened to either a 0 or a 1.
The anti-aliasing over the non-transparent areas was still OK, but where
there was transparency it was destroyed.
Thanks for looking at this for me.

Signature
Kenneth P. Turvey <kt-usenet@squeakydolphin.com>