aamir55
October 8th, 2008, 10:59 PM
hi
i have written program to trun a picture in black and white
but problem with this code is that it is very slow specialy for high resolution picture
i have a written a function which gives black and white
i m running a loop through image height and width and setting each pixel and also getting each pixel
i think that is problem why it is slow
when i run my program , i have to wait for minutes and quality of image is not so good also
code for black and white function
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
image = Me.PictureBox1.Image
Dim x As Integer
Dim y As Integer
If tolerance > 1 Or tolerance < -1 Then
Throw New ArgumentOutOfRangeException
Exit Function
End If
For x = 0 To image.Width - 1 Step 1
For y = 0 To image.Height - 1 Step 1
Dim clr As Color = image.GetPixel(x, y)
If Mode = BWMode.By_RGB_Value Then
If (CInt(clr.R) + CInt(clr.G) + CInt(clr.B)) > 383 - (tolerance * 383) Then
image.SetPixel(x, y, Color.White)
Else
image.SetPixel(x, y, Color.Black)
End If
Else
If clr.GetBrightness > 0.5 - (tolerance / 2) Then
image.SetPixel(x, y, Color.White)
Else
image.SetPixel(x, y, Color.Black)
End If
End If
Next
Next
Return image
End Function
i want it to change, i want that it should work quickly
what changes this need and any alternative method available to do that??
i have an other function for inverting the picture
it is very fast, here i m using a matrix
Public Function InvertImage(ByVal img As Image) As Boolean
Dim cm As ColorMatrix = New ColorMatrix(New Single()() _
{New Single() {-1, 0, 0, 0, 0}, _
New Single() {0, -1, 0, 0, 0}, _
New Single() {0, 0, -1, 0, 0}, _
New Single() {0, 0, 0, 1, 0}, _
New Single() {1, 1, 1, 1, 1}})
Return DrawImage(img, cm)
End Function
can i get black and white image from above function,if yes then how??
what changes i need in above function to get desire result?
thanks
i have written program to trun a picture in black and white
but problem with this code is that it is very slow specialy for high resolution picture
i have a written a function which gives black and white
i m running a loop through image height and width and setting each pixel and also getting each pixel
i think that is problem why it is slow
when i run my program , i have to wait for minutes and quality of image is not so good also
code for black and white function
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
image = Me.PictureBox1.Image
Dim x As Integer
Dim y As Integer
If tolerance > 1 Or tolerance < -1 Then
Throw New ArgumentOutOfRangeException
Exit Function
End If
For x = 0 To image.Width - 1 Step 1
For y = 0 To image.Height - 1 Step 1
Dim clr As Color = image.GetPixel(x, y)
If Mode = BWMode.By_RGB_Value Then
If (CInt(clr.R) + CInt(clr.G) + CInt(clr.B)) > 383 - (tolerance * 383) Then
image.SetPixel(x, y, Color.White)
Else
image.SetPixel(x, y, Color.Black)
End If
Else
If clr.GetBrightness > 0.5 - (tolerance / 2) Then
image.SetPixel(x, y, Color.White)
Else
image.SetPixel(x, y, Color.Black)
End If
End If
Next
Next
Return image
End Function
i want it to change, i want that it should work quickly
what changes this need and any alternative method available to do that??
i have an other function for inverting the picture
it is very fast, here i m using a matrix
Public Function InvertImage(ByVal img As Image) As Boolean
Dim cm As ColorMatrix = New ColorMatrix(New Single()() _
{New Single() {-1, 0, 0, 0, 0}, _
New Single() {0, -1, 0, 0, 0}, _
New Single() {0, 0, -1, 0, 0}, _
New Single() {0, 0, 0, 1, 0}, _
New Single() {1, 1, 1, 1, 1}})
Return DrawImage(img, cm)
End Function
can i get black and white image from above function,if yes then how??
what changes i need in above function to get desire result?
thanks