G’day Mates.
If you create a Shape, say a Rectangle, and fill and then to get an outline, draw it, you’ll get the drawn rectangle to be one pixel larger than the filled one. This is as stated in the docs, and I understand this, and why. Though this is creating quite some problem for me since I’m creating an API that excepts shapes and the paint to fill and outline them (among other things) and are supposed to procuce an image of the result.
The problem is that if you want the shape to be outlined with a translucent color, it looks really bad since generally the top left pixels touches the shape but the bottom right don’t (they are painted outside the shape).
I’ve tried the following:
-
Setting stroke-hint to PURE. Works, but since it creates two pixel outlines (as it should) it’s a no-go.
-
Auto transformation of shapes for draw/fill to scale down i pixel for draw. Works sometimes but due to rounding in the Sun API when a custom transform is used, creates inconsistent results. The outline jumps on/off the edges of the filled shape.
-
Trying different BasicStroke()s. Doesn’t work.
Some of the above DO work in certain circumstances, but then there’s the problem with turning anti aliasing on/off, which usually foils some work arounds.
My API has no control over anti-aliasing, Stroke or graphics transform, all that is parameterized. I just want to outline shapes in a good looking, pixel correct way.
Now, is there a simple (or complicated for that matter) way to get a Stoke, transform, rendering hint, or whatever, that always creates equally sized shapes dring fill/draw?
If not (which I’m almost sure of), is this how it works on other platforms (non Java) as well? For instance .NET.
ps. I noticed sketsa (SVG editor) has the same problem. As do every other Java apps i’ve seen.
ps2. Also drawing/filling cirlces don’t even paint the same pixels, sometimes there are “unpainted” pixels between the drawn circle and the filled one.
Cheers,
Mikael