Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How specify to graphics2d which colors should be of what alpha level?

 
Dan Bizman
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an image where i want to allow someone to pick which colors are of custom alpha level. So for example, they could click on pixel (x=5, y=23) which, let's say is Color(245,123,119). Then they say, that color is alpha 0.4. So everywhere in the image where that pixel appears, the graphics object will paint it with an alpha level of .4.

How would i do this?
 
Dan Bizman
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
anyone know?
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might be able to use RGBImageFilter ( here's an example of using RGBImageFilter to replace one color in an image with another color) not sure if this would work with alpha values, but it might if you specifiy alpha values on the original color.

If not, you should be able to use ColorConvertOp (converting color image to grayscale example http://www.particle.kth.se/~lindsey/JavaCourse/Book/Part1/Supplements/Chapter11/rescaleConvert.html ) this is slightly more involved, but should definitely support alpha values.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic