Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

image hightlite  RSS feed

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • 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
  • 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).
 
Goodbye moon men. Hello tiny ad:
global solutions you can do in your home or backyard
https://coderanch.com/t/708587/global-solutions-home-backyard
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!