Results 1 to 4 of 4

Thread: Pixel Values [Resolved]

  1. #1

    Thread Starter
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Pixel Values [Resolved]

    Howdy all,

    Ok, I might aswell try asking here. I've posted in the C/C++ forum because I don't believe many people come to this Assembly forum, but here goes.

    I'm wanting to get the Red Green and Blue values of a pixel. I'm wanting something like these in Assembly (MASM, but any other is fine aswell).
    Code:
    //C++ Version
    #define GetRValue(rgb)      ((BYTE)(rgb))
    #define GetGValue(rgb)      ((BYTE)(((WORD)(rgb)) >> 8))
    #define GetBValue(rgb)      ((BYTE)((rgb)>>16))
    VB Code:
    1. 'VB Version
    2. Function GetRedVal(val As Long) As Long
    3. GetRedVal = val& Mod 256
    4. End Function
    5.  
    6. Function GetGreenVal(val As Long) As Long
    7. GetGreenVal = ((val And &HFF00) / 256&) Mod 256&
    8. End Function
    9.  
    10. Function GetBlueVal(val As Long) As Long
    11. GetBlueVal = (val And &HFF0000) / 65536
    12. End Function

    Any help is greatly appreciated.

    Thanks in advance,

    Phreak
    Last edited by «°°phReAk°°»; Jul 8th, 2004 at 06:29 PM.

    Visual Studio 6, Visual Studio.NET 2005, MASM

  2. #2

    Thread Starter
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246
    I figured it out after nearly a full 24 hours:

    http://www.vbforums.com/showthread.p...95#post1730895

    Phreak

    Visual Studio 6, Visual Studio.NET 2005, MASM

  3. #3
    Fanatic Member
    Join Date
    Jan 2003
    Posts
    1,004
    code:--------------------------------------------------------------------------------
    invoke GetPixel,hDC,0,0
    ; RED
    and eax,00FF0000h
    shr eax,16

    ; BLUE
    and eax,00FF0000h

    ; GREEN
    and eax,0000FF00h
    --------------------------------------------------------------------------------

    Wouldn't it be simpler if red was:

    invoke GetPixel,hDC,0,0
    ; RED
    and eax,000000FFh
    "Can't" and "shouldn't" are two totally separate things.

    All questions should be answered. All answers should be true. That is why I post.

  4. #4

    Thread Starter
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246
    LOL. I suppose it would. The first time I figured out how I would get each value, was with blue. So I was just lazy and shifted it

    Phreak

    Visual Studio 6, Visual Studio.NET 2005, MASM

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