Results 1 to 25 of 25

Thread: GetPixel returns -1. how to fix?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Israel
    Posts
    636

    Question GetPixel returns -1. how to fix?

    Hi,

    In some times the GetPixel returns me a (-1) value.
    Why? And How can I fix it?

    Thank you,
    Arie.

  2. #2
    Frenzied Member /\/\isanThr0p's Avatar
    Join Date
    Jul 2000
    Location
    They can't stop us! We're on a misson from God.
    Posts
    1,181
    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.
    Sanity is a full time job

    Puh das war harter Stoff!

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Israel
    Posts
    636
    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.

  4. #4
    Frenzied Member /\/\isanThr0p's Avatar
    Join Date
    Jul 2000
    Location
    They can't stop us! We're on a misson from God.
    Posts
    1,181
    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.
    Sanity is a full time job

    Puh das war harter Stoff!

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Israel
    Posts
    636
    Does anyone knows another reason for the GetPixel problem?

    Thank you for posting,
    Arie.

  6. #6
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Try messing around with AutoRedraw settings.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Israel
    Posts
    636
    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.

  8. #8
    Fanatic Member twanvl's Avatar
    Join Date
    Dec 2001
    Posts
    771
    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)

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Israel
    Posts
    636
    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.

  10. #10
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    no, -1 always means error. And this is usually due to coordinates that don't exist (out of bounds).
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Israel
    Posts
    636
    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.

  12. #12
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    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.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  13. #13
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    ma,usa
    Posts
    485
    maybe it has to do with the color settings or the setting it was saved in? ie 8 or maybe 15 bit?

  14. #14
    Frenzied Member /\/\isanThr0p's Avatar
    Join Date
    Jul 2000
    Location
    They can't stop us! We're on a misson from God.
    Posts
    1,181
    well I guess it would help if you would post some code...
    Sanity is a full time job

    Puh das war harter Stoff!

  15. #15
    Addicted Member Janus's Avatar
    Join Date
    Aug 2001
    Location
    California
    Posts
    221
    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.
    "1 4m 4 1337 #4xz0r!'
    Janus

  16. #16
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    I know what the problem is

    If your picture is 320x320 pixels in size, you need to loop from 0 to 319 (320 - 1 ) 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
    Last edited by Jotaf98; Mar 1st, 2002 at 11:43 AM.
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  17. #17
    Frenzied Member /\/\isanThr0p's Avatar
    Join Date
    Jul 2000
    Location
    They can't stop us! We're on a misson from God.
    Posts
    1,181
    already said that
    seems not to help either

    maybe you should just buy a new pc
    Sanity is a full time job

    Puh das war harter Stoff!

  18. #18
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    It's not the 0-base... it's not the scale mode... huh... well... now that's weird

    Post the code please so we can have a look
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  19. #19
    Frenzied Member /\/\isanThr0p's Avatar
    Join Date
    Jul 2000
    Location
    They can't stop us! We're on a misson from God.
    Posts
    1,181
    true true
    well why don't you paste any code. I am sure you will get help then!
    Sanity is a full time job

    Puh das war harter Stoff!

  20. #20
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    Maybe he doesn't want us to steal it
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  21. #21
    Frenzied Member /\/\isanThr0p's Avatar
    Join Date
    Jul 2000
    Location
    They can't stop us! We're on a misson from God.
    Posts
    1,181
    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....
    Sanity is a full time job

    Puh das war harter Stoff!

  22. #22
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    Yeah, but if the code doesn't work it's worthless

    Look Arie, we won't be able to help unless you post the code...
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  23. #23
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    He posted his code in a different thread.

    The 3rd reply is the code:
    http://www.vbforums.com/showthread.p...hreadid=148181
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  24. #24
    Lively Member jamieoboth's Avatar
    Join Date
    Oct 2001
    Location
    UK
    Posts
    116
    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
    Ich widerstehe allem - nur nicht der Versuchung

    (I can resist anything but temptation)

  25. #25

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Israel
    Posts
    636

    Talking Thanx!!!

    It's OK!!!
    I have answered me oh right!!!
    Thank you very much!!!

    Arie.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width