Form.Line color problem - maybe bug?

RandomCoder

Well-Known Member
Licensed User
I'm attempting the icon editor challenge that I set, and by the way is open to anyone that feels up to the challenge.

In trying to create my palette I've stumbled across this problem....

First of all I load all my colors from a file into an ArrayList called PaletteColours, this works fine.
Next I wanted to draw sections of each colour on the form to use as the palette, but this is where my problem starts.

I've tried...
B4X:
For Index=0 To PaletteColour.Count-1
'... Adjust X1 and Y1 positions
Designer.Line(X1,Y1,X1+10,Y1+10,PaletteColour.Item(Index),BF)
Next
Which works fine but not with the colours that are expected, it produces pastel shades instead of the RGB values that are in the array list.
I suspect it is converting to a decimal value and so next I tried this...
B4X:
For Index=0 To PaletteColour.Count-1
'... Adjust X1 and Y1 positions
Colour=PaletteColour.Item(Index)
Designer.Line(X1,Y1,X1+10,Y1+10,Colour,BF)
Next
But still got the same... Obviously because I forgot to tell it that it was an RGB value :sign0161:
But then when I tried telling it that it's an RGB value by doing this....
B4X:
For Index=0 To PaletteColour.Count-1
'... Adjust X1 and Y1 positions
Colour=PaletteColour.Item(Index)
Designer.Line(X1,Y1,X1+10,Y1+10,RGB(Colour),BF)
Next
I get an input format exception error :confused:

Before you ask, when I place a MsgBox before the Line command I get values in this kind of format 51,0,102 and so I don't understand why it's not liking it.
Any ideas, or is this a bug :sign0085:

PS Please feel free to have a go at designing your own Icon Editor and join in the competition :sign0060:

Regards,
RandomCoder
 

RandomCoder

Well-Known Member
Licensed User
RGB expects three arguments (Red, Green and Blue).
I thought this would be the case, but within the ArrayList the stored value is in the form of Red,Green,Blue and so I was hoping on not having to split it into each separate entity, saving me an extra 3 lines of code ;)

Regards,
RandomCoder
 

agraham

Expert
Licensed User
I don't fully understand the problem you are having however a bit of a bit of clarification of what a colour is might help.

A colour is a single numeric value and can be stored as such in your ArrayList and passed to the Line method as a single value so you could use RGB() to transform the individual R,G & B values you read from your file before storing them.

The formula that the RGB function uses to calculate a colour is

colour = -1 -(255-red)*65536 -(255-green)*256 -(255-blue)

Actually this is the arithmetic equivalent of a much simpler logical operation involving shifts and logical ANDs. The -1 is there because a colour in .NET actually comprises 4 channels. The extra channel is termed the Alpha channel and determines the transparency of the colour. In B4PPC colours are fully opaque which is determined by the -1 value
 

RandomCoder

Well-Known Member
Licensed User
@Agraham, Nice insight into how colour is calculated from RGB.

My ArrayList contains values like...

205,92,92
240,128,128
250,128,114
233,150,122
255,160,122
220,20,60
255,0,0
178,34,34
139,0,0
255,192,203
255,182,193
255,105,180
255,20,147
And so on.

These are the X11 standard colours. I planned on using different files for different palettes, each loaded using the PalletColour ArrayList. My initial idea was to clear out the array and reload the desired colours into the array then create the palette on my form.

Therefore I was quite surprised when I couldn't do Designer.Line(X1,Y1,X1+10,Y1+10,RGB(PaletteColour.Item(Index)),BF) and yet the item in the array list is formatted correctly with three comma separated values to form an RGB colour.

Regards,
RandomCoder
 

agraham

Expert
Licensed User
Therefore I was quite surprised when I couldn't do Designer.Line(X1,Y1,X1+10,Y1+10,RGB(PaletteColour.Item(Index)),BF) and yet the item in the array list is formatted correctly with three comma separated values to form an RGB colour.
You have to remember that there are two different data types in B4PPC, numbers and strings, but the distinction can be blurred as B4PPC converts them into one another on occasions (and not on other occasions as you have found out).

Generally it seems that a number converts to a string and a string representing a SINGLE value converts to a number. A string like yours with separated values stays a string. Actually I don't like this - I prefer a strongly typed language where you do the conversion yourself with functions like Format().

So as dzt points out RGB() requires 3 numbers as arguments while Line() requires a single number argument to represent a colour.
 

RandomCoder

Well-Known Member
Licensed User
Thanks for the replies guys, I already understood this from Erel's response earlier.

I was just attempting to clarify to Agraham my reasoning for trying to do this.

Regards,
RandomCoder.
 
Top