Dim Temp_Colorful_To_Gray_Pic As New Colorful_To_Gray_Pics
PicBox.Image = Temp_Colorful_To_Gray_Pic.Colorful_To_Gray_Pic(PicBox.Image)
'/==============================================================================='| Class Name : Colorful_To_Gray_Pics |
'| Author : Moayad Mardini [moayad.m@gmail.com] |
'| Forum : In|Structurez [www.agdn-online.com] |
'| Blog : InTechSpot [intechspot.blogspot.com, intechspot_a-t_gmail.com] |
'| Last Edit : 25\03\2006 |
'| Framework : 2.0.50727 |
'| IDE : Microsoft Visual Studio .NET 2005 Professional Edition |
'\===============================================================================/
Public Class Colorful_To_Gray_Pics
Public Function Colorful_To_Gray_Pic(ByVal InputPic As Image) As Image
Dim TempBitmap As New Bitmap(InputPic)
Dim XIndex As Integer, YIndex As Integer, Average As Integer
For XIndex = 0 To TempBitmap.Width - 1
For YIndex = 0 To TempBitmap.Height - 1
Dim TempColor As Color = TempBitmap.GetPixel(XIndex, YIndex)
Average = Fix((Convert.ToInt32(TempColor.R) _
+ Convert.ToInt32(TempColor.G) + Convert.ToInt32(TempColor.B)) / 3)
TempBitmap.SetPixel(XIndex, YIndex, Color.FromArgb(Average, Average, Average))
Next YIndex
Next XIndex
Colorful_To_Gray_Pic = TempBitmap
End Function
End Class
'/==============================================================================='| Class Name : Colorful_To_Gray_Pics |
'| Author : Moayad Mardini [moayad.m@gmail.com] |
'| Forum : In|Structurez [www.agdn-online.com] |
'| Blog : InTechSpot [intechspot.blogspot.com, intechspot_a-t_gmail.com] |
'| Last Edit : 25\03\2006 |
'| Framework : 2.0.50727 |
'| IDE : Microsoft Visual Studio .NET 2005 Professional Edition |
'\===============================================================================/
Public Class Colorful_To_Gray_Pics
Public Function Colorful_To_Gray_Pic(ByVal InputPic As Image) As Image
Dim TempBitmap As New Bitmap(InputPic)
Dim XIndex As Integer, YIndex As Integer, YIQ As Integer
For XIndex = 0 To TempBitmap.Width - 1
For YIndex = 0 To TempBitmap.Height - 1
Dim TempColor As Color = TempBitmap.GetPixel(XIndex, YIndex)
YIQ = (TempColor.R * 0.299) + (TempColor.G * 0.587) + (TempColor.B * 0.114)
TempBitmap.SetPixel(XIndex, YIndex, Color.FromArgb(YIQ, YIQ, YIQ))
Next YIndex
Next XIndex
Colorful_To_Gray_Pic = TempBitmap
End Function
End Class