|
-
Aug 10th, 2007, 09:35 AM
#1
Thread Starter
Addicted Member
[RESOLVED] If pixel equals X...help
I'm using the MyBitmap.GetPixel(x, y) method. However it returns a value in as a color. I need to see if that color equals a predefined color. My issue is I want to code in that color myself, not compare 2 pixels. how do i see if the pixel is equal to [255,255,255] (which is white)? whenever i use Color.White it doesnt work!
also is there a way to have VB change a 24Bit image into as a 8 bit gray scale? I'm highly new to the .NET world, (incase you havent noticed )
-
Aug 10th, 2007, 11:25 AM
#2
Re: If pixel equals X...help
Define "doesn't work".
Show us your code.
-
Aug 10th, 2007, 11:50 AM
#3
Thread Starter
Addicted Member
Re: If pixel equals X...help
When i run this code, it should stop, and give me all points in the image that are black [0,0,0] in color. However it runs though the entire loop never finding a "black" pixel. The image is a black background with a single white dot (approx 20 pixels in dia.) made in MS Paint. It's a 24bpp image.
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim xx As Integer = 0
Dim yy As Integer = 0
Dim i As Integer = 0
' Create a Bitmap object from an image file.
Dim myBitmap As New Bitmap("c:\lighttest.bmp")
Dim pixelcolor As Color
' Get the color of a pixel within myBitmap.
Label1.Text = TimeOfDay()
Application.DoEvents()
'For i = 1 To 100
For xx = 1 To 200 Step 4
Application.DoEvents()
For yy = 1 To 200 Step 4
pixelcolor = myBitmap.GetPixel(xx, yy)
Label1.ForeColor = pixelcolor
Application.DoEvents()
If pixelcolor = Color.FromName("black") Then
MsgBox(xx & ", " & yy)
End If
Next
Next
'Next
MsgBox(TimeOfDay())
End Sub
-
Aug 10th, 2007, 12:28 PM
#4
Thread Starter
Addicted Member
Re: If pixel equals X...help
I got it... I needed to use "Color.FromArgb(0, 0, 0)" thanks tho!
-
Aug 10th, 2007, 09:46 PM
#5
Re: [RESOLVED] If pixel equals X...help
What's wrong with Color.Black ?
-
Aug 13th, 2007, 08:21 AM
#6
Thread Starter
Addicted Member
Re: [RESOLVED] If pixel equals X...help
 Originally Posted by penagate
What's wrong with Color.Black ?
Thats what i tried in the beginning. My image had a black background with a single white dot in the middle. I ran... If Bitmap.Getpixel = color.black then end ... and it would just run through without finding anything. I wonder if it is something to do with using a 24bbp image or something. Either way i solved it by using color.fromargb().
-
Aug 13th, 2007, 10:33 AM
#7
Re: [RESOLVED] If pixel equals X...help
I also had problems directly comparing a known pixel color to predefined color even though their rgb and Argb values were the same.
For 'normal' and particularly for user defined colors (which are nameless) you can also use the argb value for comparison - it is only one integer instead of 3+1.
Code:
'-16777216 is black, -1 is white etc.
If myBitmap.GetPixel(xx, yy).ToArgb <> Color.Black.ToArgb Then
MsgBox(xx & ", " & yy)
End If
For your second question try this link.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|