Results 1 to 16 of 16

Thread: Get Long Pixel Value

  1. #1

    Thread Starter
    Lively Member HeVa's Avatar
    Join Date
    Jul 2001
    Location
    DC
    Posts
    115

    Get Long Pixel Value

    Hi everyone.

    I need to get long pixel values out of a bitmap. I need to do this
    for many, many pixels at once so GetPixel API is not feasible. I
    found some GetDIBits and CreateDIBSection samples that seem
    to do what I want, but they automatically retrieve the pixel
    values into R, G, and B Byte values. I have tried to manipulate
    the samples to get the long values, but to no avail. Can some
    kind soul please post some sample code that gets long values
    from a DIB?

    Otherwise, does someone know how to get a long value
    from RGB values?

    Thanks, if you can help.
    H e*V a

  2. #2
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Oregon
    Posts
    962
    The RGB function lets you pass in R, G, and B to get a long color.
    Involved in: Sentience

  3. #3

    Thread Starter
    Lively Member HeVa's Avatar
    Join Date
    Jul 2001
    Location
    DC
    Posts
    115
    Gaming-world:

    Thanks! -- I should have known that such a function was
    available! It'll do as a good band-aid solution to my problem (it
    adds only a few milliseconds); I'll figure out how to get long
    values directly at some point later. Again, if anyone else has
    any ideas, I'd still appreciate them...

    Thanks
    H e*V a

  4. #4
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    The actual formula is R + G * 256 + B * 256 ^ 2. I don't think you'll get any more speed, and usually byte results are preferable... what are you doing that makes you want longs?

    It might be the other way (R * 256 ^ 2 + G * 256 + B). I'm a bit rusty there.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  5. #5

    Thread Starter
    Lively Member HeVa's Avatar
    Join Date
    Jul 2001
    Location
    DC
    Posts
    115
    Sastraxi:

    Thanks for replying. I know from your other posts on this board
    that you know your graphics stuff.

    Since you asked...

    I need to access long values and not colors, per se, because I'm
    not treating the bitmaps as graphics, but using them to store
    data (actually population levels) that need to be expressed as
    long values.

    Thanks for the formula behind the RGB function. I always
    appreciate understanding the stuff I use.
    H e*V a

  6. #6
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Well, I believe a faster way would be using the CopyMemory API:
    VB Code:
    1. '// bmBits(3x + c, y) is the array that holds the byte values. 3x + c for the 24-bit nature (rgbrgbrgbrgb) of holding the bytes.
    2.  
    3. CopyMemory LV, bmBits(x * 3, y), 3
    4. '//LV should now store your long value
    If it doesn't work, you could try LSet, but I'm not sure if you can use parts of arrays with it.
    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
    Addicted Member Janus's Avatar
    Join Date
    Aug 2001
    Location
    California
    Posts
    221
    Here's a fast, pure-vb method:
    VB Code:
    1. Public Type LongUDT
    2.     Value as Long
    3. End Type
    4. Public Type BGRAUDT
    5.     Blue as Byte
    6.     Green as Byte
    7.     Red as Byte
    8.     Alpha as Byte
    9. End Type
    10.  
    11. Dim LU as LongUDT, Color as BGRAUDT
    12. ' ...
    13. LU.Value = GetPixel(Me.hDC, X, Y)
    14. LSet Color = LU
    15. Color.Blue = Color.Blue \ 2
    16. Color.Green = Color.Green \ 2
    17. Color.Red = Color.Red \ 2
    18. LSet LU = Color
    19. Call SetPixelV(Me.hDC, X, Y, LU.Value)
    20. ' ...

    It's faster than copymemory (though only like 5%), and it doesn't require API declarations. It's a little cumbersome, though.
    "1 4m 4 1337 #4xz0r!'
    Janus

  8. #8
    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
    Hey Janus do you mind to explain why that works? (especially the dividing by two)

    and Heva, is it neccersary for you to store the data in a bitmap? I believe there is a bunch of unused infos saved... why not use a two dimensional array? (do you use RLE?)
    Sanity is a full time job

    Puh das war harter Stoff!

  9. #9
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Janus, he wanted to use it with GetDIBits and those kind of calls. In this case, I don't think you CAN use LSet (I haven't tried, but correct me if I'm wrong).
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  10. #10
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Misanthrop; Janus' code simply halves the brightness of an image (hence the / 2).
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  11. #11
    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
    alright now I feel much better
    (you help me a lot today sastraxi )
    Sanity is a full time job

    Puh das war harter Stoff!

  12. #12
    Addicted Member Janus's Avatar
    Join Date
    Aug 2001
    Location
    California
    Posts
    221
    You can use any kind of array for GetDIBits - just pass it like this:
    Code:
    GetDIBits([blah blah], ByVal VarPtr(PixelArray(0,0)), [blah blah])
    I do it all the time.
    "1 4m 4 1337 #4xz0r!'
    Janus

  13. #13
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    But can you use Lset like this?
    VB Code:
    1. Dim A(x,x) as UdtPixel
    2. Dim Col as UdtRGB
    3.  
    4. GetDIBits(...) 'whatever
    5.  
    6. LSet Col = A(0, 0) 'will this bomb out or take the values from (0-3, 0)?
    That's what I'm getting at, Janus.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  14. #14
    Addicted Member Janus's Avatar
    Join Date
    Aug 2001
    Location
    California
    Posts
    221
    LSet copies sizeof(dest) bytes from source.
    "1 4m 4 1337 #4xz0r!'
    Janus

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

  16. #16

    Thread Starter
    Lively Member HeVa's Avatar
    Join Date
    Jul 2001
    Location
    DC
    Posts
    115

    Thumbs up THANKS.

    Sastraxi, Janus, /\/\isanThr0p:

    Sorry that I neglected this thread for a while ... thanks for your
    ideas. I've already learned plenty from each of you, and I'm
    investigating what I don't yet understand. To answer your
    question /\/\isanThr0p, I do need to store the data graphically
    because the bitmaps are Maps that we'll need to view from time
    to time, but your point is a valid one, and I had considered
    using a pure array for the speed benefits. But working with
    GetDIBits and CopyMemory has given me access to the pixels
    in array form, and it seems to be extremely fast. But I'm still
    looking for the best method, as speed matters. Once again,
    thanks ... as far as I'm concerned, you're all elevated to Oracle
    status.
    H e*V a

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