Basic4ppc - Windows Mobile Development  

Go Back   Basic4ppc - Windows Mobile Development > Main Category > Questions & Help Needed
Home Register FAQ Members List Search Today's Posts Mark Forums Read

Questions & Help Needed Post any question regarding Basic4ppc.


Form.Line color problem - maybe bug?


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-30-2007, 09:03 PM
RandomCoder's Avatar
Basic4ppc Veteran
 
Join Date: May 2007
Location: UK
Posts: 485
Awards Showcase
Beta Tester 
Total Awards: 1
Default Form.Line color problem - maybe bug?

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...
Code:
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...
Code:
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
But then when I tried telling it that it's an RGB value by doing this....
Code:
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

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

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

Regards,
RandomCoder
__________________
Desktop: Pentium D 920 (2.8GHz, 4MB L2 Cache, 800MHz FSB), 1024MB, 256MB Radeon X600, 250GB HD.
Device : Axim X51v XScale 624MHz, 3.7" VGA, 64MB SDRAM, 256MB Flash ROM + 1Gb SD.

"Defeat never comes to any man until he admits it."Josephus Daniels
Reply With Quote
  #2 (permalink)  
Old 07-30-2007, 10:16 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 3,132
Default

RGB expects three arguments (Red, Green and Blue).
It will be easier to save the file with decimal value.
If you want to use this file, you need to read each row, split it (use StrSplit) to the three values and then use RGB to get the decimal value.
Reply With Quote
  #3 (permalink)  
Old 07-30-2007, 11:33 PM
RandomCoder's Avatar
Basic4ppc Veteran
 
Join Date: May 2007
Location: UK
Posts: 485
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Quote:
Originally Posted by Erel View Post
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
__________________
Desktop: Pentium D 920 (2.8GHz, 4MB L2 Cache, 800MHz FSB), 1024MB, 256MB Radeon X600, 250GB HD.
Device : Axim X51v XScale 624MHz, 3.7" VGA, 64MB SDRAM, 256MB Flash ROM + 1Gb SD.

"Defeat never comes to any man until he admits it."Josephus Daniels
Reply With Quote
  #4 (permalink)  
Old 07-31-2007, 09:30 AM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 1,683
Awards Showcase
Beta Tester Forum Contributer 
Total Awards: 2
Default

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
Reply With Quote
  #5 (permalink)  
Old 07-31-2007, 12:32 PM
RandomCoder's Avatar
Basic4ppc Veteran
 
Join Date: May 2007
Location: UK
Posts: 485
Awards Showcase
Beta Tester 
Total Awards: 1
Default

@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
__________________
Desktop: Pentium D 920 (2.8GHz, 4MB L2 Cache, 800MHz FSB), 1024MB, 256MB Radeon X600, 250GB HD.
Device : Axim X51v XScale 624MHz, 3.7" VGA, 64MB SDRAM, 256MB Flash ROM + 1Gb SD.

"Defeat never comes to any man until he admits it."Josephus Daniels
Reply With Quote
  #6 (permalink)  
Old 07-31-2007, 01:29 PM
dzt's Avatar
dzt dzt is offline
Basic4ppc Veteran
 
Join Date: May 2007
Location: Greece
Posts: 353
Awards Showcase
Beta Tester Forum Contributer 
Total Awards: 2
Default

This RGB(205,92,92) (three numeric arguments) is completely different from this RGB("205,92,92") (one string argument)
__________________
Dimitris Zacharakis
http://www.terracom.gr
Reply With Quote
  #7 (permalink)  
Old 07-31-2007, 04:55 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 1,683
Awards Showcase
Beta Tester Forum Contributer 
Total Awards: 2
Default

Quote:
Originally Posted by RandomCoder View Post
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.
Reply With Quote
  #8 (permalink)  
Old 07-31-2007, 05:47 PM
RandomCoder's Avatar
Basic4ppc Veteran
 
Join Date: May 2007
Location: UK
Posts: 485
Awards Showcase
Beta Tester 
Total Awards: 1
Default

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.
__________________
Desktop: Pentium D 920 (2.8GHz, 4MB L2 Cache, 800MHz FSB), 1024MB, 256MB Radeon X600, 250GB HD.
Device : Axim X51v XScale 624MHz, 3.7" VGA, 64MB SDRAM, 256MB Flash ROM + 1Gb SD.

"Defeat never comes to any man until he admits it."Josephus Daniels
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem With Form Size RandomCoder Questions & Help Needed 15 09-05-2008 03:03 PM
simple code: Draw line on the form xiaoye.org Code Samples & Tips 3 09-04-2008 01:54 PM
Form color in landscape mode HARRY Questions & Help Needed 8 03-07-2008 03:21 PM
Problem with VGA form.Height willisgt Questions & Help Needed 2 03-01-2008 07:57 AM
Form size problem on PC? agraham Bug Reports 12 07-05-2007 01:00 PM


All times are GMT. The time now is 07:37 AM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0