Mix colors

Mix colors

Mix colors

This tutorial shows you how to use TrackBar to get values for red, green, blue color values. To generate actual color value it use ColorToRGB function.

DownloadDownload This Tutorials

Bookmark:

Mix colors

This tutorial shows you how to use TrackBar to get values for red, green, blue color values. To generate actual color value it use ColorToRGB function.

Mix colors

Following procedure change the color of the image object.

procedure TForm1.ChangeColor(Sender: TObject);
Var
    CRed, CGreen, CBlue : TColor;
begin
    { Display mixture of colors }
    Shape1.Brush.Color:=StrToInt64Def('$'+
    IntToHex(ColorToRGB(Blue),2)+
    IntToHex(ColorToRGB(Green),2)+
    IntToHex(ColorToRGB(Red),2),0);
    { Convert integer to color value }
    CRed:=StrToInt64Def('$0000'+IntToHex(ColorToRGB(Red),2),0);    
    CGreen:=StrToInt64Def('$00'+IntToHex(ColorToRGB(Green),2)+'00',0);
    CBlue:=StrToInt64Def('$'+IntToHex(ColorToRGB(Blue),2)+'0000',0);
    { display circles for each color }
    Image1.Canvas.Brush.Color:=CRed;
    Image1.Canvas.Pen.Color:=CRed;
    Image1.Canvas.Ellipse(X-25, Y-40, X+25, Y+10);
    Image1.Canvas.Brush.Color:=CGreen;
    Image1.Canvas.Pen.Color:=CGreen;
    Image1.Canvas.Ellipse(X-40, Y-15, X+10, Y+35);
    Image1.Canvas.Brush.Color:=CBlue;
    Image1.Canvas.Pen.Color:=CBlue;
    Image1.Canvas.Ellipse(X-10, Y-15, X+40, Y+35);
end;

When changing track bar position, use following method to change color intensity.

procedure TForm1.RedTrackBarChange(Sender: TObject);
begin
    Red:=RedTrackBar.Position;
    ChangeColor(Self);
end;

procedure TForm1.GreenTrackBarChange(Sender: TObject);
begin
    Green:=GreenTrackBar.Position;
    ChangeColor(Self);
end;

procedure TForm1.BlueTrackBarChange(Sender: TObject);
begin
    Blue:=BlueTrackBar.Position;
    ChangeColor(Self);
end; 

This one draws three circles with basic colors at startup.

procedure TForm1.FormCreate(Sender: TObject);
begin
    Red:=255;
    Green:=255;
    Blue:=255;
    X:=Image1.Width Div 2;
    Y:=Image1.Height Div 2;
    Image1.Canvas.Brush.Color:=clRed;
    Image1.Canvas.Pen.Color:=clRed;
    Image1.Canvas.Ellipse(X-25, Y-40, X+25, Y+10);
    Image1.Canvas.Brush.Color:=cllime;
    Image1.Canvas.Pen.Color:=cllime;
    Image1.Canvas.Ellipse(X-40, Y-15, X+10, Y+35);
    Image1.Canvas.Brush.Color:=clBlue;
    Image1.Canvas.Pen.Color:=clBlue;
    Image1.Canvas.Ellipse(X-10, Y-15, X+40, Y+35);
end; 

Download This Delphi Tutorials.

Download materials for this article (Delphi - Tutorials)

Download - Mix-Colors.zipMix-Colors.zip
       File size: 4 KB, File type: zip
       Total downloads: 326, Upload date: February 10 - 2009

Enea :: May 07-2009 :: 07:16 PM

I   want to paint a  bird on tree 
Please  help me.I  don't know what colour to  do  the bird

sam :: September 18-2010 :: 11:21 AM

Hi there i am a painter i need some basic information about mixing paint 

Leave a comment