• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

image hightlite

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi

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?

PS img2 i can only create programmatically

thanks
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).
 
I miss the old days when I would think up a sinister scheme for world domination and you would show a little emotional support. So just look at this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic