[Gambas-user] About Image.Pixel

Bruce Steers bsteers4 at gmail.com
Tue Aug 15 13:24:08 CEST 2023


On Tue, 15 Aug 2023 at 12:18, Bruce Steers <bsteers4 at gmail.com> wrote:

>
>
> On Tue, 15 Aug 2023 at 12:13, Bruce Steers <bsteers4 at gmail.com> wrote:
>
>>
>>
>> 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.
>>
>
> Aah so after Benoits advise i guess we should create image like this...
>
>   Dim hImg As New Image(1, 1, Color.red)
>   hImg.Format = "BGRA"
>

oops I guess the value order should be read a BGRA too

B = Hex(Lsr(aInt[0], 24) And &HFF, 2)
G = Hex(Lsr(aInt[0], 16) And &HFF, 2)
R = Hex(Lsr(aInt[0], 8) And &HFF, 2)
A = Hex(aInt[0] And &HFF, 2)
Print a, r, G, B

B = Hex(255 - Lsr(hImg[0, 0], 24) And &HFF, 2)
G = Hex(Lsr(hImg[0, 0], 16) And &HFF, 2)
R = Hex(Lsr(hImg[0, 0], 8) And &HFF, 2)
A = Hex(hImg[0, 0] And &HFF, 2)

Print a, r, G, B

I'll sit me back down, pretty sure you know what to do to convert anyway
now :)
Respects
BruceS
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20230815/b08116d8/attachment-0001.htm>


More information about the User mailing list