Results 1 to 6 of 6

Thread: [RESOLVED] VB6: how get RGB from ARGB color?

  1. #1

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,904

    Resolved [RESOLVED] VB6: how get RGB from ARGB color?

    i need get Red, Green and Blue from ARGB... how can i do it?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  2. #2
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,852

    Re: VB6: how get RGB from ARGB color?

    Joaquim, not sure what format you're talking about, but RGB is always in an ARGB format. The "A" is just the alpha channel. Ignore it, and you've got RGB.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  3. #3

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,904

    Re: VB6: how get RGB from ARGB color?

    see these test code(ok combined GDIPLUS with GDI, but it's only a test):
    Code:
    Dim color As Long
                GdipBitmapGetPixel hBitmap, X, Y, color
                If (color = CLR_INVALID) Then Exit For
                Point = ConvertPositon3DTo2D(DrawPixelPoints(X), WorldSize)
                SetPixelV DestinationHDC, Point.X, Point.Y, color
    i only get black and red colors... that's why i must convert the GdipBitmapGetPixel() color to RGB.
    i can't use the GdipBitmapSetPixel(), because the destination is HDC form and not a bitmap.
    VB6 2D Sprite control

    To live is difficult, but we do it.

  4. #4

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,904

    Re: VB6: how get RGB from ARGB color?

    i found these code:
    Code:
    GdipBitmapGetPixel hBitmap, X, Y, color
                r = (color And &HFF)
                g = ((color \ &H100) And &HFF)
                b = ((color \ &H10000) And &HFF)
                If (color = CLR_INVALID) Then Exit For
                Point = ConvertPositon3DTo2D(DrawPixelPoints(X), WorldSize)
                SetPixelV DestinationHDC, Point.X, Point.Y, RGB(r, g, b)
    but, sometimes, i get red line and i don't know why....
    is these calculation correct?
    Attachment 179361
    VB6 2D Sprite control

    To live is difficult, but we do it.

  5. #5
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,120

    Re: VB6: how get RGB from ARGB color?

    Consider this snippet

    Code:
    Option Explicit
    
    Private Sub Form_Load()
        Dim color   As Long
        Dim r       As Byte
        Dim g       As Byte
        Dim b       As Byte
        
        color = &HFFFFFF12
        r = color And &HFF
        Debug.Assert r = &H12
        
        color = &HFFFF34FF
        g = ((color \ &H100) And &HFF)
        Debug.Assert g = &H34                  ' <--- fails
        g = (color And &HFF00&) \ &H100&
        Debug.Assert g = &H34                  ' <--- ok
        
        color = &HFF56FFFF
        b = ((color \ &H10000) And &HFF)
        Debug.Assert b = &H56                  ' <--- fails
        b = (color And &HFF0000) \ &H10000
        Debug.Assert b = &H56                  ' <--- ok
    End Sub
    The idea is to first And (apply) the mask and then divide to extract the component.

    cheers,
    </wqw>

  6. #6

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,904

    Re: VB6: how get RGB from ARGB color?

    thank you so much for all.. i continue had some bad colors with some images... but, for now, i can draw an image on 3D plane.... i must use DIB's for speed and more
    now i must fix another problem: the red lines(i take of the fill brush) are the not calculated line points.
    i will back on other topic.
    thanks for all
    VB6 2D Sprite control

    To live is difficult, but we do it.

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