Re: Anti-aliasing in image clipping to non-rectangular sub-images
John B. Matthews wrote:
In article <48a4f9d9$0$4009$b9f67a60@news.newsdemon.com>,
Knute Johnson <nospam@rabbitbrush.frazmtn.com> wrote:
Daniele Futtorovic wrote:
On 15/08/2008 02:03, Knute Johnson allegedly wrote:
Daniele Futtorovic wrote:
On 14/08/2008 17:20, Knute Johnson allegedly wrote:
Well there's a truth that it took me a while to learn and that
is that you can't draw alpha into an image.
Must be jolly interesting if it's something that took you a while
to learn. So... what does that sentence mean?
If you have an image, you basically can't draw on it (with the
usual Graphics(2D) methods) and reduce the alpha value of the
pixels in the image. Say you have a pixel that is white with an
alpha of 255. There is no way to draw on the image to change that
pixel's alpha to another value.
I thought that was what the AlphaComposites were for...
Unless of course you use an AlphaComposite with a value of Clear.
That will change it to a black pixel with an alpha of 0.
... ah.
To get this right, are you positively sure there is no way? Not
even playing with XOR paint?
I can't swear that XOR paint won't but I couldn't make it work. Of
course that is not definitive :-).
I've been tinkering with Knute's examples and reading the API. I'd be
grateful if someone could comment critically on what I think I
understand:
0. You can paint with any color you want: opaque, translucent,
transparent. That does not modify the alpha component of the destination
pixel, except to overwrite the pixel with entirely new ARGB values.
(That's how I interpreted, "can't draw alpha into an image.")
Assuming you are using the default AlphaComposite which is SrcOver.
1. You can change the alpha component of a pixel in a BufferedImage
using get/setRGB() or getRaster(), but you have to loop through the
pixels to effect the change.
Yes.
2. Each of the 12 Composites in AlphaComposite implements a rule for
combining source and destination pixels when drawing. When you draw in a
Graphics2D that has a Composite set, each destination pixel is set
according to the Composite's rule and the alpha component of the chosen
color.
Yes. And you can change the alpha value of an image with the right
AlphaComposite.
3. The rule in AlphaComposite.Clear says, "Anything that's painted
becomes transparent black [Color(0, true)] in the destination image," as
if it were a stencil with the painted part punched out. When this
stencil is later drawn, any underlying image pixels "show through" the
transparent ones.
Yes.
4. The rule in AlphaComposite.Src says, "Any painted pixel gets set to
the the current color and alpha." Knute used SrcOver for the rings of
fuzziness, but Src is identical for a transparent destination.
Yes. For the fuzzy ring I used SrcOver because that is the default
AlphaComposite. In the FuzzyHole example the result is the same if you
use Src, DstOver, or DstAtop. You would have to check actual pixel
values to confirm that but they look the same.
IBM has an excellent article on the Porter-Duff rules and a Java program
you can use to experiment with.
http://www.ibm.com/developerworks/java/library/j-mer0918/
These rules while looking simple are very complicated and the results
are not (at least to me) always obvious.
If you play with that CompositeIt program, check the 4 AlphaComposites
above. Be sure the set the destination alpha to 0 to simulate the alpha
hole in the mask image.
So while my "truth" that you can't draw alpha into an image isn't 100%
true, it pretty much sums up what you have to do.
--
Knute Johnson
email s/nospam/knute2008/
--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access