I’ve been reading the API for Graphics2D
and have seen examples of all the available composite modes (that are similar to photoshop blend modes) but I can’t see a way to draw a source image to a target buffered image In a colour that I have specified, for example my source image is a white opaque circle on a fully transparent background, how do I draw using this to a buffer so a coloured circle is drawn.
I would prefer not to construct an intermediate image for performance reasons, is this possible with the api?
EDIT: I have added an image that hopefully helps to show the operation I am trying to describe. This is a common way to draw sprites in open GL etc and I am just wondering how to use the Graphics2D
API to do the same thing.
2
Answers
Specify the location of your image in the imageName below.
Is is possible using the API but you have to write your own
ImageProducer
subclass similar toFilteredImageSource
but with two input images instead of one. But because of that the end result will require more lines of code than a manual implementation and won’t be any more efficient. Alternatively you can use the existingFilteredImageSource
and write anImageFilter
subclass that wraps the 2nd image and does the hard work.Poke me if you decide you want to go with any of these routes.