Thread: Getting back the Red, Green, and Blue

  1. #1
    Captain - Lover of the C
    Join Date
    May 2005
    Posts
    341

    Getting back the Red, Green, and Blue

    If I use the code:
    #define RGB32BIT(a, r, g, b) ((b) + (g << 8) + (r << 16) + (a << 24)

    buffer[y * lpitch32 + x] = RGB32BIT(0, 0, 255, 0);

    How do I get back the alpha, red, green, and blue values? Something like?

    UCHAR b = buffer[y * lpitch32 + x];
    UCHAR g = buffer[y * lpitch32 + x] >> 8;
    UCHAR r = buffer[y * lpitch32 + x] >> 16;
    UCHAR a = buffer[y * lpitch32 + x] >> 24;

  2. #2
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,263
    what you got should work theoretically?
    Last edited by no-one; 05-13-2005 at 09:36 PM.
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  3. #3
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    BYTE Red=(PixelColor & 0xFF0000) >> 16;
    BYTE Green=(PixelColor & 0xFF00) >>8;
    BYTE Blue=(PixelColor & 0xFF);

  4. #4
    Captain - Lover of the C
    Join Date
    May 2005
    Posts
    341
    Turns out I was right after all. But the reply above mine works too even though the '& 0xFF' is pointless if you shift it anyway.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. linker 2019 issues
    By werdy666 in forum C++ Programming
    Replies: 3
    Last Post: 02-25-2009, 04:12 AM
  2. Gradient fills
    By pronecracker in forum Windows Programming
    Replies: 5
    Last Post: 04-29-2007, 11:55 AM
  3. String parser
    By sand_man in forum C Programming
    Replies: 13
    Last Post: 08-13-2005, 10:33 AM
  4. OpenGL, loading BMP Textures?
    By Zeusbwr in forum Game Programming
    Replies: 12
    Last Post: 12-09-2004, 05:16 PM
  5. Odd 3D Invis Objects?
    By Zeusbwr in forum Game Programming
    Replies: 4
    Last Post: 12-07-2004, 07:01 PM