Results 1 to 7 of 7

Thread: Color to Black & White

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2000
    Location
    India
    Posts
    2,288

    Color to Black & White

    How do I change a bitmap being displayed from color to Black & white ?

  2. #2
    Megatron
    Guest
    Not too sure on this, but I think you have to add the red, green and blue values together, and take the average of them (by diving them by 3).

  3. #3
    Megatron
    Guest
    VB Code:
    1. Private Declare Function SetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long) As Long
    2. Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
    3.  
    4. Private Sub Command1_Click()
    5.  
    6.     For x = 0 To Picture2.Width / Screen.TwipsPerPixelX
    7.         For y = 0 To Picture2.Height / Screen.TwipsPerPixelY
    8.             DoEvents
    9.             lColor = GetPixel(Picture2.hdc, x, y)
    10.             lRed = lColor Mod &H100
    11.             lGreen = Int(lColor / &H100) Mod &H100
    12.             lBlue = Int(lColor / &H10000) Mod &H100
    13.             t = Abs(Int((lRed + lGreen + lBlue) / 3))
    14.             SetPixel hdc, x, y, RGB(t, t, t)
    15.         Next y
    16.     Next x
    17.    
    18. End Sub

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Aug 2000
    Location
    India
    Posts
    2,288
    Thanks Megatron.
    Btw, if you are working in Win 2000, you can use SetColorAdjustment to get a negative. You can even increase or decrease the brightness, gamma levels etc

  5. #5
    Junior Member
    Join Date
    Mar 2000
    Posts
    25

    Cool

    How to then save this as a black and white bitmap?

    TIA

  6. #6
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    I think VBEMPIRE has the right values, it's not just / 3.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  7. #7
    jim mcnamara
    Guest
    the CCIR recomended use for RGB -> monochrome conversion is luminance for use on monochrome monitors.

    Y = 0.299*R + 0.587*G + 0.114*B

    color = RGB(Y,Y,Y)

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