Finding the black Pixel(getpixel), Wont work. Plz Help

SickelSell
10-24-2006, 09:04 PM
Well, Here's my code...It just freezes...If anybody could make it that it finds the darkest pixel...i would love them.

Dim x As Long
Dim y As Long
Dim pixel As Color



Dim TempBmp As New Bitmap(pPicture.Image.Size.Width, pPicture.Image.Size.Height)
TempBmp = pPicture.Image
Do
For y = 50 To TempBmp.Width - 15 Step 4
For x = 50 To TempBmp.Width - 15 Step 4
pixel = TempBmp.GetPixel(x, y)
If pixel.ToArgb = Color.Black.ToArgb Then
MsgBox(x & " " & y)
Exit Do
End If
Next x
Next y
Loop

OnErr0r
10-24-2006, 09:22 PM
You're hardcoding quite a few values there. For instance, the starting position and width minus fifteen. I'm not sure why you're stepping four either. Anyway, if the width is less than sixty five, nothing will ever be found and you're caught in an endless loop (do/loop). You can just get rid of the do/loop.

Probably the biggest problem I see is that y would normally be to TempBmp.Height, not Width.

SickelSell
10-24-2006, 09:29 PM
You're hardcoding quite a few values there. For instance, the starting position and width minus fifteen. I'm not sure why you're stepping four either. Anyway, if the width is less than sixty five, nothing will ever be found and you're caught in an endless loop (do/loop). You can just get rid of the do/loop.

Probably the biggest problem I see is that y would normally be to TempBmp.Height, not Width.

Ok, Fixed that...Heres my new code, But now the X and Y values are not changing.

Private Sub Timer1_tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick


If IsTimeBetween(txtstart.Text, txtstop.Text) = True Then
PictureBox1.Load("C:\WORK.gif")
Dim TempBmp As New Bitmap(PictureBox1.Image.Size.Width, PictureBox1.Image.Size.Height)
TempBmp = PictureBox1.Image
TempBmp.SetPixel(51, 51, Color.Black)

For y = 0 To TempBmp.Height - 1
For x = 0 To TempBmp.Width - 1
pixel = TempBmp.GetPixel(x, y)
'If pixel.ToArgb = Color.Black.ToArgb Then
MsgBox(x & " " & y)
' End If
Next x
Next y


End If
End Sub


The setpixel is there to test it. As you can see the if pixel.toargb and the end if are commented just so i can see what the X and the Y's are at.

OnErr0r
10-24-2006, 09:54 PM
You'll want to set a breakpoint and step through your code. I'm not sure why a timer is running. If x and y remain zero, then TempBmp is probably Nothing.

Btw, this line of code does nothing:

Dim TempBmp As New Bitmap(PictureBox1.Image.Size.Width, PictureBox1.Image.Size.Height)

It really only serves to dim a bitmap, but you're setting to another bitmap on the next line. Instead, consider something like this:

Dim TempBmp As Bitmap = DirectCast(PictureBox1.Image, Drawing.Bitmap)

Or possibly this:

Dim TempBmp As New Bitmap("c:\work.gif")
TempBmp.SetPixel(51, 51, Color.Black)
PictureBox1.Image = TempBmp

SickelSell
10-24-2006, 10:10 PM
You'll want to set a breakpoint and step through your code. I'm not sure why a timer is running. If x and y remain zero, then TempBmp is probably Nothing.

Btw, this line of code does nothing:

Dim TempBmp As New Bitmap(PictureBox1.Image.Size.Width, PictureBox1.Image.Size.Height)

It really only serves to dim a bitmap, but you're setting to another bitmap on the next line. Instead, consider something like this:

Dim TempBmp As Bitmap = DirectCast(PictureBox1.Image, Drawing.Bitmap)

Or possibly this:

Dim TempBmp As New Bitmap("c:\work.gif")
TempBmp.SetPixel(51, 51, Color.Black)
PictureBox1.Image = TempBmp

I still haven't figured out why it's staying 0...Also I fixed it with the Casting option, Thanks :D ^_^

I have everything under timer1_tick is that wrong?

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum