Results 1 to 4 of 4

Thread: [RESOLVED] i want to increase the darkness of a color ?

  1. #1

    Thread Starter
    Frenzied Member maged's Avatar
    Join Date
    Nov 2002
    Location
    Egypt
    Posts
    1,040

    Resolved [RESOLVED] i want to increase the darkness of a color ?

    Dear all,
    i have a color variable that contains of course a color value, how can i increase the blue degree of the color by a certain value.

    for example i have a degree of blue and i want to make it darker.

    i think to make it darker and retain the original color i will have to increase the three rgb components the exact value. but how can i do this ???


    thank you

    rgds

  2. #2
    Junior Member
    Join Date
    May 2006
    Posts
    26

    Re: i want to increase the darkness of a color ?

    This should work. It's just the opposite of a brightness adjuster that I use.

    Subtract a value from each pixel's colour components (red, green, and blue). The bigger darknessVal, the darker the image will become.

    VB Code:
    1. Dim pixelColour As Color
    2. Dim x,y As Integer
    3. Dim darknessVal as Byte
    4. ...
    5. For x = 0 to PhotoBmp.Width - 1
    6.    For y = 0 to PhotoBmp.Height - 1
    7.       pixelColour = photoBmp.GetPixel(x, y)
    8.  
    9.       red = pixelColour.R - darknessVal
    10.       green = pixelColour.G - darknessVal
    11.       blue = pixelColour.B - darknessVal
    12.  
    13.       pixelColour = Color.FromArgb(red, green, blue)
    14.       photoBmp.SetPixel(x, y, pixelColour)
    15.    Next
    16. Next

    But don't forget NOT to let red, green, or blue go below 0 after the subtraction. I didn't include the error checking code for reasons of clarity.

    Bear in mind this is my first attempt at answering a question, and I'm a beginner myself.
    I'm using VB.NET 2005 Express

  3. #3
    Junior Member
    Join Date
    May 2006
    Posts
    26

    Re: i want to increase the darkness of a color ?

    I think you can see how to increased the blueness of an image.

    The bigger bluenessVal, the bluer the image will become.

    VB Code:
    1. ...
    2. blue = pixelColour.B + bluenessVal
    3. ...

    In a similar loop to the above, but leaving the other colour values alone.
    I'm using VB.NET 2005 Express

  4. #4

    Thread Starter
    Frenzied Member maged's Avatar
    Join Date
    Nov 2002
    Location
    Egypt
    Posts
    1,040

    Re: i want to increase the darkness of a color ?

    thank you for answering

    why did u assume that i am trying to darken an image ??? i dint say that

    i have a color variable and i want to make it darker.

    but in any case your code will work in all cases

    thank you very much for the code, and cu around

    rgds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width