How do I change a bitmap being displayed from color to Black & white ?
Printable View
How do I change a bitmap being displayed from color to Black & white ?
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).
VB Code:
Private Declare Function SetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long) As Long Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long Private Sub Command1_Click() For x = 0 To Picture2.Width / Screen.TwipsPerPixelX For y = 0 To Picture2.Height / Screen.TwipsPerPixelY DoEvents lColor = GetPixel(Picture2.hdc, x, y) lRed = lColor Mod &H100 lGreen = Int(lColor / &H100) Mod &H100 lBlue = Int(lColor / &H10000) Mod &H100 t = Abs(Int((lRed + lGreen + lBlue) / 3)) SetPixel hdc, x, y, RGB(t, t, t) Next y Next x End Sub
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
How to then save this as a black and white bitmap?
TIA
I think VBEMPIRE has the right values, it's not just / 3.
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)