01.
Public
Function
PureBW(
ByVal
image
As
System.Drawing.Bitmap,
Optional
ByVal
Mode
As
BWMode = BWMode.By_Lightness,
Optional
ByVal
tolerance
As
Single
= 0)
As
System.Drawing.Bitmap
02.
Dim
x
As
Integer
03.
Dim
y
As
Integer
04.
If
tolerance > 1
Or
tolerance < -1
Then
05.
Throw
New
ArgumentOutOfRangeException
06.
Exit
Function
07.
End
If
08.
For
x = 0
To
image.Width - 1
Step
1
09.
For
y = 0
To
image.Height - 1
Step
1
10.
Dim
clr
As
Color = image.GetPixel(x, y)
11.
If
Mode = BWMode.By_RGB_Value
Then
12.
If
(
CInt
(clr.R) +
CInt
(clr.G) +
CInt
(clr.B)) > 383 - (tolerance * 383)
Then
13.
image.SetPixel(x, y, Color.White)
14.
Else
15.
image.SetPixel(x, y, Color.Black)
16.
End
If
17.
Else
18.
If
clr.GetBrightness > 0.5 - (tolerance / 2)
Then
19.
image.SetPixel(x, y, Color.White)
20.
Else
21.
image.SetPixel(x, y, Color.Black)
22.
End
If
23.
End
If
24.
Next
25.
Next
26.
Return
image
27.
End
Function
28.
29.
Enum
BWMode
30.
By_Lightness
31.
By_RGB_Value
32.
End
Enum