Recent

Author Topic: color from integer  (Read 11111 times)

zoiddani

  • New Member
  • *
  • Posts: 29
color from integer
« on: January 07, 2011, 09:12:03 pm »
Hello,
I've experencied the following problem:
Code: [Select]
Image1.Canvas.Pixels[x,y]:= an_integer;This code will only make colors like green, yellow, black and red. I couldn't make any other color. How could i get e.g. blue or any other color from an integer?

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: color from integer
« Reply #1 on: January 07, 2011, 09:22:13 pm »
Code: [Select]
TGraphicsColor = -$7FFFFFFF-1..$7FFFFFFF;
You should use hexadecimal value.

Just for an example: http://www.w3schools.com/html/html_colors.asp
« Last Edit: January 07, 2011, 09:28:21 pm by typo »

fabienwang

  • Sr. Member
  • ****
  • Posts: 449
  • Lazarus is the best
    • My blog
Re: color from integer
« Reply #2 on: January 07, 2011, 10:57:42 pm »
Image1.Canvas.Pixels[x,y].Color !
I'm using Arch Linux.
Known for: CPickSniff, OpenGrabby
Contributed to: LazPaint

zoiddani

  • New Member
  • *
  • Posts: 29
Re: color from integer
« Reply #3 on: January 08, 2011, 09:15:39 am »
Yeah i thought about that too. But how can i convert my integer to a TGraphicsColor?
Because IntToHex returns a string.
Also should i declare my variable for the color like this:
Code: [Select]
type mycolor= -$7FFFFFFF - 1..$7FFFFFFF; ?
Thank you!

Leledumbo

  • Hero Member
  • *****
  • Posts: 8834
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: color from integer
« Reply #4 on: January 08, 2011, 09:33:10 am »
Quote
Yeah i thought about that too. But how can i convert my integer to a TGraphicsColor? Because IntToHex returns a string.
You don't have to. Integers from all supported bases (2,8,10,16) are treated the same by the compiler. It's just sometimes we need to write them in another base to ease reading (humans can't work as fast as computers dude, at least in this case). So, in order to declare, for instance, yellow you do either one of this:
Code: [Select]
var
  MyColor: TGraphicsColor;
begin
  MyColor := $00FFFF; // base 16
  MyColor := 65535; // base 10
  MyColor := %000000001111111111111111; // base 2
  MyColor := &000177777; // base 8

PAEz

  • New Member
  • *
  • Posts: 29
Re: color from integer
« Reply #5 on: January 09, 2011, 04:01:36 pm »
Sounds like you need to learn some fundementals, especially if you want to play with graphics.
If your going to have fun with graphics with code then you really need to learn how those graphics are stored in memory.
Things you shoud probably look up are hex,binary,decimal and learn how they relate.  Then learn different number types like integer, byte,word....what your trying to learn there is that numbers like integers are made of multiple amounts of bytes, this is important so you can understand that a pixel which represent Red, Green, Blue and alpha would need to be made of 4 bytes, which can also be seen as one integer.  This will help you understand how graphics are stored in memory and why the color needs to be set the way it does.

A color of RGB is made of 3 bytes.  A byte is a number that can have the range of 0 to 255.  In hex 0 to 255 is 00 to FF.
So to make a color of r,g,b where red is 255, green is 0 and blue is 255 it would be FF00FF.


Im really sorry I cant be of more help but you really should google the things I mention above and try to learn them, one day youll get it and graphics are so much fun.
Lazarus 0.9.29  Windows XP sp3
E6400 2gig ram 7900GTX 512meg

I have a shocking memory and am a crap coder, so take everything I say with a grain of doubt

 

TinyPortal © 2005-2018