A1VBCode Forums

convert image


http://www.a1vbcode.com/vbforums/Topic13003.aspx

By jay12 - 7/20/2005

I have a simple program to convert an image in a picture box into as grayscale image ,from what i have been told it is possible to then change that image in to a black and white image with certain levels of gray being converted to black and lower levels of gray being converted into white how would i do this
here is my code to change into gray scale
what would i need to add to this code



Private Sub cmdGray_Click()
Pic.ScaleMode = vbPixels
X = Pic.ScaleWidth
y = Pic.ScaleHeight
For i = 0 To y - 1
For j = 0 To X - 1
pixel = Pic.Point(j, i)
red = pixel Mod 256
green = ((pixel And &HFF00) / 256& Mod 256&
blue = (pixel And &HFF0000) / 65536

gs = ((red * 30) + (green * 59) + (blue * 11)) / 100
Pic.PSet (j, i), RGB(gs, gs, gs)

Next
Next
Pic.ScaleMode = vbTwips
End Sub

 

thanks

By RoofRabbit - 7/28/2005

I'd just take the value in "pixel" and compare it to 1/2 it's maximum value. If less, set pixel = 0, else set to max value (depending color display mode used).