i have bufferedimage(img1) which i render on the screen, then if user mouseover it i want hightlite it with yellow (exemple yellow with 0.5 alpha)
what i think to do that create another bufferedimage(img2, yellow with 0.5 alpha) with hight and wight as img1 and merge it with img1
but problem is img1 have transparent pixels(0 alpha) and if render over it all area of img1 be merget with img2.
Is there a way to merge pixels of img1 which don't have 0 alpha value with java composit functionality or a need do this by hand?
I can think of two possibilities for this:
The basic idea is to use the Area class to make a highlighted border for your image.
Make an Area the size of the highlight rectangle size.
Substract an Area the size of the first/original image from it.
You can fill this area, now just a border, with your 0.5 alpha yellow color.
Then you can either:
1 — fill the area in the graphic component and draw your image centered in/above it, or
2 — make a new BufferedImage the size of the highlight rectangle size and the same type as your first/original image; make an area the size of the BufferedImage and subtract an area the size of the first/original image, fill the area in the new BufferedImage as above. Then draw the source/original image centered into the new BufferedImage. Draw this new BufferedImage in your graphic component.
The two areas will be initialized with rectangles that have different origins, the one in option 2 will be located at (0,0).