[Gambas-user] About Image.Pixel
Bruce Steers
bsteers4 at gmail.com
Tue Aug 15 13:13:55 CEST 2023
On Mon, 14 Aug 2023 at 23:37, Bruce Steers <bsteers4 at gmail.com> wrote:
>
>
> On Mon, 14 Aug 2023, 21:19 Fabien Bodard, <gambas.fr at gmail.com> wrote:
>
>> Hi,
>>
>> Dim hImg As New Image(1, 1, Color.red)
>> dim a as Integer[]
>>
>> a = hImg.Pixels
>> Print a[0]
>> Print hImg[0, 0]
>>
>> result :
>> -65536
>> 16711680
>>
>>
>> Why ?
>>
>> --
>> Fabien Bodard
>>
>
> According to wiki Image[x,y] returns a "colour"
> Image.pixels[n] will be from an array of "32 bits integers"
>
> I don't understand it but seems could be a difference?
>
>
> Respects
> BruceS
>
I think i figured it out..
I noticed the warning on the wiki Color page..
http://gambaswiki.org/wiki/comp/gb.qt4/color
In Gambas, the alpha color component is inverted in comparison to standard
color coding. In other words, an alpha component of zero is fully opaque,
and an alpha component of 255 is fully transparent
So I used this code that converts to hex values...
Public Sub Form_Open()
Dim hImg As New Image(1, 1, Color.red)
Dim aInt As Integer[]
Print "red = "; Color.Red
aInt = hImg.Pixels
Print aInt[0]
Print hImg[0, 0]
Dim A, R, G, B As String
A = Hex(Lsr(aInt[0], 24) And &HFF, 2)
R = Hex(Lsr(aInt[0], 16) And &HFF, 2)
G = Hex(Lsr(aInt[0], 8) And &HFF, 2)
B = Hex(aInt[0] And &HFF, 2)
Print A, R, G, B
A = Hex(255 - Lsr(hImg[0, 0], 24) And &HFF, 2) ' Note this line uses 255-
as wiki says Alpha values in gambas are reversed
R = Hex(Lsr(hImg[0, 0], 16) And &HFF, 2)
G = Hex(Lsr(hImg[0, 0], 8) And &HFF, 2)
B = Hex(hImg[0, 0] And &HFF, 2)
Print A, R, G, B
End
results..
red = 16711680
-65536
16711680
FF FF 00 00
FF FF 00 00
Note for the Image[n,n] array i use 255- on the alpha value to reverse it.
It seems the Pixels[] array does not reverse the alpha value but the
Image[] array does
I have no idea how to convert the 1st 32bit alpha part as a color integers
all i have is that Hex conversion but i think i found the problem.
Respects
BruceS
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20230815/3afdacb5/attachment.htm>
More information about the User
mailing list