Results 1 to 16 of 16

Thread: GetPixel Problems...

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2001
    Location
    Kingston, Ontario, Canada
    Posts
    74

    GetPixel Problems...

    Hey,

    I'm using the GetPixel function to read every pixel in an image, then write it to a text file... that's been pretty simple. But after a bit of time it seems to just give up and starts spewing out either red (255) or an error (-1), any ideas?
    To err is human, to really mess up, you need a computer.

  2. #2
    Lively Member wazup guys's Avatar
    Join Date
    Apr 2001
    Location
    in a compressed datastream on the web
    Posts
    114
    i would need to see what the image looks like and your code
    wahuah

    talk to me about macromedia flash mx, Visual Basic, Vbscript, Html

    [email protected]
    [email protected]
    [email protected]

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 2001
    Location
    Kingston, Ontario, Canada
    Posts
    74
    OK, it happens on all sorts of images, not just one..... Seems to affect large images more though...

    and code?

    VB Code:
    1. Option Explicit
    2. Dim i%, j%, col&
    3.  
    4. Private Sub Form_Load()
    5.     picw = 23 'Set picture width in pixels
    6.     pich = 30 'Set picture height in pixels
    7. End Sub
    8.  
    9. Private Sub Command1_Click()
    10. For i = 0 To pich - 1
    11. For j = 0 To picw - 1
    12.     col = GetPixel(picPicture.hdc, j, k)
    13.     Text1.Text = Text1.Text & col & vbCrLf
    14. Next j
    15. Next i
    To err is human, to really mess up, you need a computer.

  4. #4
    Member Yhoko's Avatar
    Join Date
    May 2002
    Posts
    47
    Did you set picPicture.AutoRedraw to True? I think this may be your mistake...
    - Yhoko


    Try my Games
    * [VB6] YDK - Yhoko's Development Kit
    * [VB6] HackV1 - two-player puzzle/strategy
    * [VB6] Xen - extended Gen

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jun 2001
    Location
    Kingston, Ontario, Canada
    Posts
    74
    It is set to true, has been the whole time. I didn't think it would make a difference because of it being GetPixel.... bu it's set to true.
    To err is human, to really mess up, you need a computer.

  6. #6
    Hyperactive Member Knowledge_is_Et's Avatar
    Join Date
    Dec 2001
    Location
    An Oak.
    Posts
    305
    I've had similar problems. Getpixel uses a pixel scale. Maybe the scale is different?
    Now returning to the world of VB. Please make sure your seatbelts are securely fastened and all trays are in their upright and locked position.

  7. #7
    Lively Member wazup guys's Avatar
    Join Date
    Apr 2001
    Location
    in a compressed datastream on the web
    Posts
    114
    ok time for some working code

    sub [were you need the code]
    dim x,y,temp as long

    open "c:\data.txt" for output as #1

    for y = 0 to picture1.scalehieght
    for x = 0 to picture1.scalewidth
    temp = picture1.point(x,y)
    print #1, temp
    doevents
    next x
    next y

    close #1
    end sub

    you can put the code in the sub rutien you need it
    if your going to be doing it to alot of images i suggest that u have a image box and load the image first to the image box and transfer the width and hieght to the picture box and the picture box should have sclaemode of 3-pixel.

    just incase whats you email so i can email a vb project to you if it doesnt work
    wahuah

    talk to me about macromedia flash mx, Visual Basic, Vbscript, Html

    [email protected]
    [email protected]
    [email protected]

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Jun 2001
    Location
    Kingston, Ontario, Canada
    Posts
    74
    My email? Type some random letters in.... any will do... then add @jigabug.net to it and it'll get to me...

    I'll let you know how it works...

    Update: Works great, I had to add a -1 to the end of these two lines in order to avoid it generating a -1, but other then that it works perfectly. Thanks again!

    VB Code:
    1. For y = 0 To Picture1.ScaleHeight
    2. For x = 0 To Picture1.ScaleWidth
    Last edited by Jigabug; Jun 22nd, 2002 at 07:43 AM.
    To err is human, to really mess up, you need a computer.

  9. #9
    PowerPoster Arbiter's Avatar
    Join Date
    Sep 2000
    Location
    Manchester
    Posts
    2,276
    I've highlighted a bit in bold for you....

    VB Code:
    1. Option Explicit
    2. Dim i%, j%, col&
    3.  
    4. Private Sub Form_Load()
    5.     picw = 23 'Set picture width in pixels
    6.     pich = 30 'Set picture height in pixels
    7. End Sub
    8.  
    9. Private Sub Command1_Click()
    10. For i = 0 To pich - 1
    11. For j = 0 To picw - 1
    12.     col = GetPixel(picPicture.hdc, j, [b]k[/b])
    13.     Text1.Text = Text1.Text & col & vbCrLf
    14. Next j
    15. Next i
    Gentile or Jew,
    O you who turn the wheel and look to windward,
    Consider Phlebas, who was once handsome and tall as you...

  10. #10
    Member Yhoko's Avatar
    Join Date
    May 2002
    Posts
    47
    *smiles* Sorry didn't see that. Jigabug I highly recommend you to use the 'Option Explicit' statement in any of your modules so you don't get into this problem again.
    - Yhoko


    Try my Games
    * [VB6] YDK - Yhoko's Development Kit
    * [VB6] HackV1 - two-player puzzle/strategy
    * [VB6] Xen - extended Gen

  11. #11
    PowerPoster Arbiter's Avatar
    Join Date
    Sep 2000
    Location
    Manchester
    Posts
    2,276
    The interesting thing is that he has.

    He must have it declared globally somewhere else...

    I've just noticed he's edited his post above to say that he's got it sorted. He's using point, so it will be slower - but hey, as long as it works.....
    Gentile or Jew,
    O you who turn the wheel and look to windward,
    Consider Phlebas, who was once handsome and tall as you...

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Jun 2001
    Location
    Kingston, Ontario, Canada
    Posts
    74
    Yes,

    All of the variables used in the program are globally declared along with a whole bunch of functions in a module that must be 75 pages or more of code... That code was just the snippit causing problems.

    The other thing is that it's still not working right on larger images, it handles the 100x100 fine now, but i have a 340x480 image that I need it to be able to work on, and it freezes. Any ideas?

    Another thing, Yhoko hit one nail on the head, when I set autoredraw to true it was the form, not the picture... The GetPixel option works now, but I'm not sure which would be faster...
    To err is human, to really mess up, you need a computer.

  13. #13
    Lively Member wazup guys's Avatar
    Join Date
    Apr 2001
    Location
    in a compressed datastream on the web
    Posts
    114
    if you can get getpixel to work right it will be faster just by a couple of seconds. could you possibly email it to me to see it to see whats going wrong
    wahuah

    talk to me about macromedia flash mx, Visual Basic, Vbscript, Html

    [email protected]
    [email protected]
    [email protected]

  14. #14
    Lively Member wazup guys's Avatar
    Join Date
    Apr 2001
    Location
    in a compressed datastream on the web
    Posts
    114
    although my code isn't 75 pages long i just timed it on a 800x600 image and it took me 4 secs i dont think thats to long.
    what is picture.scalemode set to.
    wahuah

    talk to me about macromedia flash mx, Visual Basic, Vbscript, Html

    [email protected]
    [email protected]
    [email protected]

  15. #15

    Thread Starter
    Lively Member
    Join Date
    Jun 2001
    Location
    Kingston, Ontario, Canada
    Posts
    74
    Wazup,

    a) You're not getting your hands on the code.

    b) I have them both working now

    c) 4 seconds? Using which method?
    To err is human, to really mess up, you need a computer.

  16. #16
    Lively Member wazup guys's Avatar
    Join Date
    Apr 2001
    Location
    in a compressed datastream on the web
    Posts
    114
    4 secs using point on a 800 x 600 pixel image
    wahuah

    talk to me about macromedia flash mx, Visual Basic, Vbscript, Html

    [email protected]
    [email protected]
    [email protected]

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