Parsi Coders

نسخه‌ی کامل: سورس کد تبدیل تصویر رنگی به سیاه سفید
شما در حال مشاهده نسخه آرشیو هستید. برای مشاهده نسخه کامل کلیک کنید.
Convert an image to pure Black-and-White

کد پی‌اچ‌پی:
InstructionsTo use this function, first pass the desired image to it,
 and 
then pass the Mode parameterwhich determines if the image 
should be processes based on the total RGB value of a pixel 
or the lightness of a pixel.
 
Then pass the Tolerance valuewhich is a decimal which must be >= -and 

سورس کد :

کد پی‌اچ‌پی:
Public Function PureBW(ByVal image As System.Drawing.BitmapOptional ByVal Mode As BWMode BWMode.By_LightnessOptional ByVal tolerance As Single 0) As System.Drawing.Bitmap
        Dim x 
As Integer
        Dim y 
As Integer
        
If tolerance Or tolerance < -1 Then
            
Throw New ArgumentOutOfRangeException
            
Exit Function
        
End If
        For 
0 To image.Width 1 Step 1
            
For 0 To image.Height 1 Step 1
                Dim clr 
As Color image.GetPixel(xy)
                If 
Mode BWMode.By_RGB_Value Then
                    
If (CInt(clr.R) + CInt(clr.G) + CInt(clr.B)) > 383 - (tolerance 383Then
                        image
.SetPixel(xyColor.White)
                    Else
                        
image.SetPixel(xyColor.Black)
                    
End If
                Else
                    If 
clr.GetBrightness 0.5 - (tolerance 2Then
                        image
.SetPixel(xyColor.White)
                    Else
                        
image.SetPixel(xyColor.Black)
                    
End If
                
End If
            
Next
        Next
        
Return image
    End 
Function
    
Enum BWMode
        By_Lightness
        By_RGB_Value
    End Enum