VB 如何将一张BMP的彩图改成黑白的呢?

来源:百度知道 编辑:UC知道 时间:2024/06/27 08:19:41
用这个办法不行:DrawGrayBitmap picSrc.hdc, 0, 0, 258, 194

我要的是像画图工具的操作一样,黑白!
一楼回答运行报错:
---------------------------
常数、固定长度字符串、数组、用户定义类型以及 Declare 语句不允许作为对象模块的 Public 成员。

不好意思,我是新手不懂得如何调用你的函数,能否说下如何调用?

Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Declare Function SetPixelV Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long) As Long

Function GetRValue&(ByVal rgbColor&)
GetRValue = rgbColor And &HFF
End Function

Function GetGValue&(ByVal rgbColor&)
GetGValue = (rgbColor And &HFF00&) / &HFF&
End Function

Function GetBValue&(ByVal rgbColor&)
GetBValue = (rgbColor& And &HFF0000) / &HFF00&
End Function

Sub ChangetoGray(ByVal SrcDC&, ByVal nx&, ByVal ny&, Optional ByVal nMaskColor& = -1)
Dim rgbColor&, Gray&
Dim RValue&, GValue&, BValue&
Dim dl&

rgbColor = GetPixel(SrcDC, nx, ny)

If rgbColor = nMaskColor Then GoTo Release:

RValue = GetRValue(rgbColor)
GValue = GetGValue(rgbColor)
BValue =