0

I have a picturebox control where I load a 50x160 BMP image, using this:

Picture1.Picture = LoadPicture(App.Path & "\test.bmp")

Once the picture is loaded, I want to get the color of a specific pixel:

GetPixel(Picture1.hDC, 0, 0)
Picture1.Point(0, 0)

I have tried the 8000 pixels (using a loop, obviously) and every function call (GetPixel and Point) always return -1. The first time I test this it works perfectly, and now it magically doesn't work.

Any ideas?

cdonts
  • 9,304
  • 4
  • 46
  • 72

1 Answers1

0

are you sure the picture is fully loaded?

have a look at the following project:

'1 form with
'  1 picturebox: name=Picxture1
Option Explicit

Private Sub Form_Load()
  Picture1.Picture = LoadPicture("c:\temp\thieu.jpg")
  Caption = CStr(Picture1.Point(0, 0))
End Sub

Private Sub Form_Resize()
  Picture1.Move 0, 0, ScaleWidth, ScaleHeight
End Sub

Private Sub Picture1_Click()
  Caption = CStr(Picture1.Point(0, 0))
End Sub

Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  Caption = CStr(Picture1.Point(X, Y))
End Sub

when the form loads it loads the picture, and directly shows the color of 0,0 in the caption .. which is -1 because the picture is not loaded yet

when you push the mousebutton down on the picture it will show the color of that coordinate, when you release the button (and complete a click) it will show you the color of the coordinate 0,0

Hrqls
  • 2,944
  • 4
  • 34
  • 54