Thread: Colorblind

  1. #1
    Registered User darketernal's Avatar
    Join Date
    Sep 2001
    Posts
    41

    Colorblind

    I can't get the RGB Values.

    Im Using a ColorDialog1 , in Borland Builder 5.

    on Button1->ColorDialog1->Execute()

    a screen appears where you can choose from the colors

    red = 0 to 255
    green = 0 to 255
    blue = 0 to 255

    How to retrieve these values from the ColorDialog?

    If you can't solve that problem, im also having something else

    For instance

    Edit1->Text = "Hello World";

    if i want to seperate "Hello" + "World" from this string so i would get

    Edit2->Text = "Hello";
    Edit3->Text = "World";

    How would i go about?

    These seemingly easy tasks are in reality much harder then it seems -_-

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Probably the very next page in the manual.
    Having displayed the control, the next logical step would be how to get the answer back.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User darketernal's Avatar
    Join Date
    Sep 2001
    Posts
    41
    -sigh- although i expected an answer like that, it still hurts >.<

    As said easier said then done, have a look again

    http://uploader.ws/upload/200705/rgb.jpg

    To display this screen when we click a button i simply use.

    ColorDialog1->Execute();

    It shows the screen that you see above.

    In the Dialog you see 3 rgb values, respectivly

    R = 0
    G = 255
    B = 0

    How do i retrieve the 3 individual R G B values.? (seriously i checked the manual and the internet a couple of times)

  4. #4
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Your image is not visible...

    Have you looked in the Web: http://www.functionx.com/bcb/applica...orselector.htm

    About splitting string in the tokens - you can use stringstream for example
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  5. #5
    Registered User darketernal's Avatar
    Join Date
    Sep 2001
    Posts
    41
    Sorry for the imagine not being visible, the page died on me, anyway i managed to fix the problem myself into obtaining the RGB values from a random given color.

    Code:
    void __fastcall TForm1::Button1Click(TObject *Sender)
    {
    ColorDialog1->Execute();
    CSpinEdit1->Value = ColorDialog1->Color;
    Memo1->Color = CSpinEdit1->Value;
    
    CSpinEdit2->Value = CSpinEdit1->Value;
    CSpinEdit3->Value = CSpinEdit1->Value/256;
    CSpinEdit4->Value = CSpinEdit1->Value/256/256;
    
    if(CSpinEdit2->Value > 255)
    {
    CSpinEdit6->Value = CSpinEdit3->Value * 256;
    CSpinEdit2->Value = CSpinEdit1->Value - CSpinEdit6->Value;
    }
    if(CSpinEdit3->Value > 255 < 65280 )
    {
    
    CSpinEdit3->Value = CSpinEdit3->Value - CSpinEdit2->Value/256;
    }
    if(CSpinEdit1->Value >= 65280)
    {
    CSpinEdit5->Value = CSpinEdit4->Value * 256 * 256 + CSpinEdit2->Value;
    CSpinEdit3->Value = CSpinEdit1->Value - CSpinEdit5->Value;
    CSpinEdit3->Value = CSpinEdit3->Value/256;
    }
    }
    Although simple it was a lot trickier then i expected to obtain the 3 values as i had to figure out how they designed the color scheme and appointed colours on the coordinates. I didn't want to create an entire new Colordialog from scratch,just get the rgb from the value given. It was tricky to see how much portion of every given primairy color was appointed to each color coordinate. Thanks so much for the time you've people decidate on helping people.
    Last edited by darketernal; 05-20-2007 at 05:53 AM.

  6. #6
    Registered User darketernal's Avatar
    Join Date
    Sep 2001
    Posts
    41
    http://uploader.ws/upload/200705/raw_example.jpg A very rough example on how to retrieve the RGB values from any given random colour.

    roughly explained basically its a multiplication

    256 for red
    256*256 for Green
    256*256*256 for blue

    From there i did this crazy division and it somehow worked out lol.

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    So basically you wanted something like
    R = CSpinEdit1->Value & 0xFF;
    G = ( CSpinEdit1->Value >> 8 ) & 0xFF;
    B = ( CSpinEdit1->Value >> 16 ) & 0xFF;

    Going the other way
    CSpinEdit1->Value = ( B << 16 ) | ( G << 8 ) | R;
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed