On 2nd look, it appears to be dead simple - embarrisingly so....
1) Make sure you image you are drawing onto only has 1 bit transparency, and starts off initialised to clear+transparent.
1
| getGraphicsConfiguration.createCompatibleImage(width,height,Transparency.BITMASK); |
worked for me.
Though i'm sure one of BufferedImage's more complex constructors could do it too.
2) Don't forget to turn on the text anti-alias hint.
Then, draw the text in 2 passes as I mentioned before.
3) First pass, draw with your matte colour, any pixels touched will be turned from 0x00000000, to 0xFFrrggbb. (where rrggbb is your matte colour).
4) Second pass, draw with your text colour, the pixels touched will already contain 0xFFrrggbb and so will be replaced with the desired matte/colour blend - according to the alpha values generated by the anti-aliasing text rasterizer.
No need to mess around with AlphaComposites at all!
:edit:
Nvm, doesn't work due to the rounding ^_^
When drawing the matte, pixels are only touched with an alpha >127.
I'm sure it's possible & simple to fix though...