Hi,
In some times the GetPixel returns me a (-1) value.
Why? And How can I fix it?
Thank you,
Arie.
Printable View
Hi,
In some times the GetPixel returns me a (-1) value.
Why? And How can I fix it?
Thank you,
Arie.
is it possible that you used it out of the image bounds? GetPixel uses pixels for coordinates not the vb twips so if you set your picturebox or whatever you use to twips and use them to get the position that might be the reason for the -1.
In my picturebox I use from (0,0) to (320,320).
is it right? because it works on the most of the times.
I don't know why it gives me (-1).
Thank you,
Arie.
well I don't know, but the most probable reason for getting a -1 would be beeing out of bounds remember if you pic is 320 pixels wide the range is from 0 to 319 not 320, but it might be something else I don't know about.
Does anyone knows another reason for the GetPixel problem?
Thank you for posting,
Arie.
Try messing around with AutoRedraw settings.
My picture's autoredraw is set to false and if it wasn't my game won't work! anyone with other options??
please help!
thank you,
Arie.
I think -1 is the default window color, if your Picturebox's BackColor is set to vbButtonFace you'll get that color.
Just set the Picturebox's BackColor to something else (You can for example use the GetSysColor API to get the actual color of vbButtonFace)
but,
when I do the GetPixel function I do it for the picMain.hdc.
not to Form1.hdc.
any other ideas?
thank you anyway,
Arie.
no, -1 always means error. And this is usually due to coordinates that don't exist (out of bounds).
Ok, but my GetPixel is IN_BOUNDS!!!!
That's why I'm asking what else could it be?
It not happens all the time, it's pretty rare...
Most of the times it works fine...
But when it happens it ruins my game!
What can it be? please help!
Thank you so far,
Arie.
Well about the autoredraw thing maybe this is part of a bigger thing... why does your surface need to be False?
Other than that, just loop until your answer is not -1.
maybe it has to do with the color settings or the setting it was saved in? ie 8 or maybe 15 bit?
well I guess it would help if you would post some code...
If your picturebox is not autoredraw, if a window is covering it, the GetPixel call will most likely fail because the pixel at that location has been erased by the window now covering it.
Set your picturebox's autoredraw to true, and then once you draw to it, call .Refresh and VB will copy the changes to the screen for you. This prevents both flicker, and other windows from erasing your image.
I know what the problem is :)
If your picture is 320x320 pixels in size, you need to loop from 0 to 319 (320 - 1 :D ) for both the X and Y, because the coordinates are 0-based so the 0 counts too. Basically you're looping trough 321 pixels instead of 320 :rolleyes: :p
already said that
seems not to help either
maybe you should just buy a new pc :D
It's not the 0-base... it's not the scale mode... huh... well... now that's weird :D
Post the code please so we can have a look ;)
true true
well why don't you paste any code. I am sure you will get help then!
Maybe he doesn't want us to steal it :D
Yeah I collect all kinds of buggy code...
well yeah maybe we could kill the bugs, if he'd post it...
that would make it worth stealing though....
Yeah, but if the code doesn't work it's worthless :p
Look Arie, we won't be able to help unless you post the code...
He posted his code in a different thread.
The 3rd reply is the code:
http://www.vbforums.com/showthread.p...hreadid=148181
THAT SNEAK! He obviously didn't trust us...:(
We aren't good enough for his needs... *Sniff*
Excuse me....
MWAAAAAAAAAHAAAAAA! burble burble
Sigh. I'm ok, the counseling has worked, all I had to do was hit a chair with a rubber baseball bat ;)
It's OK!!!
I have answered me oh right!!!
Thank you very much!!!
Arie.