Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

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).
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic