INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Delphi Imaging

How do I get the RGB and CMYK values of a TColor? by djjd47130
Posted: 26 May 11 (Edited 27 May 11)

I have built an object specifically to provide all the RGB and CMYK values together. It's designed to be used on components as a published property to be shown in the Object Inspector. It breaks down Red, Green, Blue, Cyan, Magenta, Yellow, and Black values, as well as the original TColor.

Code was extracted from a larger library of mine.

CODE

[code]
// for automatic syntax highlighting see FAQ102-6487
////////////////////////////////////////////////////////////////////////////////
//  Delphi 7 Unit "JDGraphics.pas"
//    JD's Custom Graphics Library
//  Classes:
//    TJDColor: TPersistent - Custom TColor wrapper with RGB and CMYK properties
////////////////////////////////////////////////////////////////////////////////

unit JDGraphics;

interface
 
uses
  Classes, Controls, SysUtils, Windows, StdCtrls, ExtCtrls, Graphics, StrUtils,
  JPEG, Messages, Variants, Forms, Dialogs, Buttons, ComCtrls, ImgList;

////////////////////////////////////////////////////////////////////////////////
//                                TJDColor
//             Custom color wrapper providing RGB and CMYK values
////////////////////////////////////////////////////////////////////////////////

type
  TJDColor = class;

  TColEvent = procedure(Sender: TObject) of object;

  TJDColor = class(TPersistent)
    private
      FColor: TColor;
      fEvent: TColEvent;
      procedure SetColor(Value: TColor);
      function GetRed: Integer;
      function GetGreen: Integer;
      function GetBlue: Integer;
      procedure SetRed(Value: Integer);
      procedure SetGreen(Value: Integer);
      procedure SetBlue(Value: Integer);
      function GetCyan: Integer;
      function GetMagenta: Integer;
      function GetYellow: Integer;
      function GetBlack: Integer;
      procedure SetCyan(Value: Integer);
      procedure SetMagenta(Value: Integer);
      procedure SetYellow(Value: Integer);
      procedure SetBlack(Value: Integer);
      procedure RaiseEvent;
    public
      constructor Create;
      property Red: Integer read GetRed write SetRed;
      property Green: Integer read GetGreen write SetGreen;
      property Blue: Integer read GetBlue write SetBlue;
      property Cyan: Integer read GetCyan write SetCyan;
      property Magenta: Integer read GetMagenta write SetMagenta;
      property Yellow: Integer read GetYellow write SetYellow;
      property Black: Integer read GetBlack write SetBlack;
    published
      property Color: TColor read FColor write SetColor;
      property OnEvent: TColEvent read fEvent write fEvent;
  end;



implementation



////////////////////////////////////////////////////////////////////////////////
//                                 TJDColor
//     Stores TColor and provides read/write of RGB and CMYK color values
////////////////////////////////////////////////////////////////////////////////

constructor TJDColor.Create;
begin
  Self.Color:= clBlack;
  Self.RaiseEvent;
end;

procedure TJDColor.SetColor(Value: TColor);
begin
  Self.FColor:= Value;
  Self.RaiseEvent;
end;

function TJDColor.GetRed: Integer;
begin
  Result:= GetRValue(FColor);
end;

function TJDColor.GetGreen: Integer;
begin
  Result:= GetGValue(FColor);
end;

function TJDColor.GetBlue: Integer;
begin
  Result:= GetBValue(FColor);
end;

procedure TJDColor.SetRed(Value: Integer);
begin
  Self.FColor:= RGB(Value, GetGreen, GetBlue);
  RaiseEvent;
end;

procedure TJDColor.SetGreen(Value: Integer);
begin
  Self.FColor:= RGB(GetRed, Value, GetBlue);  
  RaiseEvent;
end;

procedure TJDColor.SetBlue(Value: Integer);
begin
  Self.FColor:= RGB(GetRed, GetGreen, Value);  
  RaiseEvent;
end;

function TJDColor.GetCyan: Integer;
begin
  Result:= GetCValue(FColor);
end;

function TJDColor.GetMagenta: Integer;
begin
  Result:= GetMValue(FColor);
end;

function TJDColor.GetYellow: Integer;
begin
  Result:= GetYValue(FColor);
end;

function TJDColor.GetBlack: Integer;
begin
  Result:= GetBValue(FColor);
end;

procedure TJDColor.SetCyan(Value: Integer);
begin
  Self.FColor:= CMYK(Value, GetMagenta, GetYellow, GetBlack);
  RaiseEvent;
end;

procedure TJDColor.SetMagenta(Value: Integer);
begin
  Self.FColor:= CMYK(GetCyan, Value, GetYellow, GetBlack);    
  RaiseEvent;
end;

procedure TJDColor.SetYellow(Value: Integer);
begin
  Self.FColor:= CMYK(GetCyan, GetMagenta, Value, GetBlack);  
  RaiseEvent;
end;

procedure TJDColor.SetBlack(Value: Integer);
begin
  Self.FColor:= CMYK(GetCyan, GetMagenta, GetYellow, Value);
  RaiseEvent;
end;

procedure TJDColor.RaiseEvent; //Postback for components
begin
  if assigned(Self.fEvent) then begin
    Self.fEvent(Self);
  end;
end;

end.
 

[/code]


Back to Embarcadero: Delphi FAQ Index
Back to Embarcadero: Delphi Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close