This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Hi, I want to color byte array of image pixels with any color say Color(25,25,50). please help. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Hi, I want to color byte array of image pixels with any color say Color(25,25,50). please help." Watch "Hi, I want to color byte array of image pixels with any color say Color(25,25,50). please help." New topic
Author

Hi, I want to color byte array of image pixels with any color say Color(25,25,50). please help.

Surajsingh Thakur
Ranch Hand

Joined: Sep 09, 2008
Posts: 124

Hi All,
I want to color byte array of image pixels with any color say Color(25,25,50) preserving intensity of the original color.
Formula to calculate intensity of color: 0.3*R + 0.59*G + 0.11*B

Suppose current color of a image pixel is Color(50,25,23).
i.e.
current color - Red part - 50, Green part - 25 & blue part - 23.
apply color - Red part - 25, Green part - 25 & blue part - 50.

if I use bitwise AND opration I will get
Red part - 25, Green part - 25 & blue part - 23. ie. Color(25,25,23). thus intensity changes.
As you can see apply color has blue part prominant that means the end result should be some shade of blue with same intensity as the current color.
Can anybody give me exact formula or logic for this.

BE (Computer Science) SCJP 4 (80%) SCWCD 5 (97%) IBM CAD(98%) IBM CAppD(100%) IBM SD(100%)
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41024
    
  43
Look like you need to solve the equation

0.3*R_new + 0.59*G_new + 0.11*B_new = 0.3*R_old + 0.59*G_old + 0.11*B_old

If you change just the B value from 23 to 59 then that reduces to something like

0.3*R_new + 0.59*G_new = 26.78

Pick any acceptable new value for R_new or G_new, and the other can be calculated.


Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hi, I want to color byte array of image pixels with any color say Color(25,25,50). please help.
 
Similar Threads
Structure Size
getting the color of a particular pixel from an image loaded in applet
Image Color Changing
Image color changing
How to code a button with image