-
Nov 22nd, 2020, 12:15 PM
#1
Thread Starter
PowerPoster
[RESOLVED] VB6: how get RGB from ARGB color?
i need get Red, Green and Blue from ARGB... how can i do it?
-
Nov 22nd, 2020, 12:40 PM
#2
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.
-
Nov 22nd, 2020, 12:55 PM
#3
Thread Starter
PowerPoster
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.
-
Nov 22nd, 2020, 01:38 PM
#4
Thread Starter
PowerPoster
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
-
Nov 22nd, 2020, 02:29 PM
#5
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>
-
Nov 22nd, 2020, 02:49 PM
#6
Thread Starter
PowerPoster
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|