home *** CD-ROM | disk | FTP | other *** search
- { Project ColRep.DPR Delphi 2.0 Demos
-
- Description:- ColRep.Dpr Project:-
-
- Demonstrates the use of:
-
- 1) 'GetColor'
- 2) 'GetPalIndex'
- 3) 'SetPalIndex'
- 4) 'ColorReplace'
- 5) 'RGB'
-
- Date of Origin: 15/04/96
- Original Author: Andrew Hutchison
- Modification History:
-
- Date Person Change
- ----------------------------------------------------
- 15/04/96 A Hutchison Created
-
- (c) Copyright Media Architects Inc. 1996.
- All rights reserved. No part of this program may be
- photocopied, reproduced, translated to another programming
- language or transported to any computer system without the
- prior written consent of Media Architects Inc.}
-
- unit UColRep;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls, ExtCtrls, Buttons, Spin, OleCtrls, ImageKnife32, Menus;
-
- type
- TForm1 = class(TForm)
- Bevel1: TBevel;
- Picbuf1: TPicbuf;
- GroupBox1: TGroupBox;
- RedVal: TSpinEdit;
- GreenVal: TSpinEdit;
- BlueVal: TSpinEdit;
- Color: TSpeedButton;
- Label1: TLabel;
- Label2: TLabel;
- Label3: TLabel;
- MainMenu1: TMainMenu;
- File1: TMenuItem;
- LoadImage: TMenuItem;
- N1: TMenuItem;
- Exit: TMenuItem;
- OpenDialog: TOpenDialog;
- Picbuf2: TPicbuf;
- procedure ColorClick(Sender: TObject);
- procedure LoadImageClick(Sender: TObject);
- procedure Picbuf1MouseDown(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- procedure ExitClick(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure FormActivate(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- {$R *.DFM}
-
- {-------------------------------------------------------------------------------}
- {Set the color of the second PicBuf to the values of the SpinEdit boxes
-
- Note:- The advantage of using these 'SpinEdit' boxes, is that you can define a
- lower limit and upper limit for the returned value. In otherwords it won't let
- you enter 300 for example which is not a valid RGB colour. Is also returns an
- integer number by default so no conversions are required}
- procedure TForm1.ColorClick(Sender: TObject);
- begin
- PicBuf2.BackColor := RGB(RedVal.Value,GreenVal.Value,BlueVal.Value); {Set Color}
- end;
-
- {-------------------------------------------------------------------------------}
- {Load an Image using its extension.}
- procedure TForm1.LoadImageClick(Sender: TObject);
- begin
- {Execute Dialog Box}
- if OpenDialog.execute then
- begin
- {Set FileName}
- Picbuf1.FileName:=OpenDialog.Filename;
- {Call Load Method}
- Picbuf1.Load;
- end;
- end;
-
- {-------------------------------------------------------------------------------}
- {When you click on an Image, the color at the mouse location is stored. That
- color is then replaced with the color that is displayed in the 'Shape Object'.
- This code replaces only colors that match 100% the picked color.}
- procedure TForm1.Picbuf1MouseDown(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- Var
- Xpos,Ypos:Integer;
- ChangeColor,SelectedColor:LongInt;
- begin
- {Set trap to avoid non valid points}
- try
- {Get Mouse Down Location - in pixels - Delphi Default}
- XPos := Picbuf1.ScreenToImageX(X);
- YPos := Picbuf1.ScreenToImageY(Y);
- {Get user selected color - Edit Box Values}
- ChangeColor := RGB(RedVal.Value,GreenVal.Value,BlueVal.Value);
- {24 Bit Images}
- if Picbuf1.ColorDepth = 24 then
- begin
- {Get Color at Mouse Down Location}
- SelectedColor := Picbuf1.GetColor(XPos,YPos); {Call Method}
- {Replace Color}
- Picbuf1.ColorReplace(SelectedColor,SelectedColor,0, ChangeColor); {Call Method}
- end
- else{Images with Palettes}
- begin
- {Get Color at Palette Location}
- SelectedColor := Picbuf1.GetPalIndex(XPos, YPos); {Call Method}
- {Set Color a Palette Location}
- Picbuf1.SetPalColor(SelectedColor, ChangeColor); {Call Method}
- end;
- {Error Trap for Non - Valid Locations}
- except
- MessageDLG('Non Valid Point or Non Valid Image - OK to Continue.', mtConfirmation,
- [mbOK], 0);
- end;
- end;
-
- {-------------------------------------------------------------------------------}
- {Exit Application}
- procedure TForm1.ExitClick(Sender: TObject);
- begin
- Halt;
- end;
-
- {-------------------------------------------------------------------------------}
- {Defaults}
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- Application.HintPause :=10;
- Application.HintColor:=clAqua;
- end;
-
- procedure TForm1.FormActivate(Sender: TObject);
- begin
- Picbuf1.FileName:= '..\images\bambi1.bmp';
- Picbuf1.Load;
- PicBuf2.BackColor := RGB(RedVal.Value,GreenVal.Value,BlueVal.Value); {Set Color}
- end;
-
-
-
- end.
-