Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Another problem about TColor

se_arese_are Member Posts: 11
Hi to all,
first I'm sorry for all this questions.
My problem is that I want to convert a TColot data that is a 4 byteexadecimal number into three integers which rapresent RGB channels.
TColor hold this information in his first trhee bytes.
I would like to know if there is a function for picking TColor Byte per Byte. A function that returns the first byte alone.

Sorry for the bad explanation and thanks for the help.

P.S. = zibadian I've solved my last problem as you said, thank you very much!

Comments

  • zibadianzibadian Member Posts: 6,349
    : Hi to all,
    : first I'm sorry for all this questions.
    : My problem is that I want to convert a TColot data that is a 4 byteexadecimal number into three integers which rapresent RGB channels.
    : TColor hold this information in his first trhee bytes.
    : I would like to know if there is a function for picking TColor Byte per Byte. A function that returns the first byte alone.
    :
    : Sorry for the bad explanation and thanks for the help.
    :
    : P.S. = zibadian I've solved my last problem as you said, thank you very much!
    :
    You can use this code to convert a 4-byte integer into a 4-byte array:
    [code]
    type
    TColorArray = array[1..4] of byte;
    var
    RGB: TColorArray;
    C: TColor;
    begin
    C := clRed;
    Move(C, RGB, 4);
    // Process the color as individual bytes in an array using RGB.
    end;
    [/code]
  • se_arese_are Member Posts: 11
    This is perfect!! Really Smart!!
    And What about the type cast?? I'd need to convert This single Byte to an integer value. I've looked into the helps but I didn't find any function! Does this function exists??

  • zibadianzibadian Member Posts: 6,349
    : This is perfect!! Really Smart!!
    : And What about the type cast?? I'd need to convert This single Byte to an integer value. I've looked into the helps but I didn't find any function! Does this function exists??
    :
    :
    All integer types can be assigned to one-another without conversion. If you assign a small integer to a large one:
    [code]
    var
    b: byte;
    i: integer;
    begin
    i := b;
    end;
    [/code]
    then the value will stay the same. If the assignment is the other way around, you might truncate the value to the number of bytes in the new integer type:
    [code]
    var
    b: byte;
    i: integer;
    begin
    i := 5050;
    b := i;
    // b will either be 186 or 19, I'm not sure which
    end;
    [/code]
  • se_arese_are Member Posts: 11
    How ignorant I am!!!
    Thank you very much again, you're the man!!!

Sign In or Register to comment.