home *** CD-ROM | disk | FTP | other *** search
- { Project GreyNeg.DPR Delphi 2.0 Demos
-
- Description:- GreyNeg.Dpr Project:-
-
- Demonstrates the use of:
-
- 1) 'GrayScale'
- 2) 'Mirror'
- 3) 'Rotate'
- 4) 'Negate'
- 5) 'ImportDib & DuplicateDib'
-
- 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 UGreyNeg;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- Menus, Buttons, ExtCtrls, StdCtrls, OleCtrls, ImageKnife32, Spin;
-
- type
- TForm1 = class(TForm)
- PicbufVisible: TPicbuf;
- PicbufOriginal: TPicbuf;
- RadioGroup: TRadioGroup;
- Bevel1: TBevel;
- ProcessImage: TSpeedButton;
- Undo: TSpeedButton;
- MainMenu1: TMainMenu;
- File1: TMenuItem;
- LoadImage: TMenuItem;
- SaveImageAs: TMenuItem;
- N1: TMenuItem;
- Exit: TMenuItem;
- Angle: TSpinEdit;
- OpenDialog: TOpenDialog;
- procedure LoadImageClick(Sender: TObject);
- procedure PicbufOriginalChange(Sender: TObject);
- procedure ProcessImageClick(Sender: TObject);
- procedure UndoClick(Sender: TObject);
- procedure ExitClick(Sender: TObject);
- procedure SaveImageAsClick(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure RadioGroupClick(Sender: TObject);
- procedure FormActivate(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
- var
- Form1: TForm1;
-
- function ValidFormat(FileName:String):Boolean;{See Below}
-
- implementation
-
- {$R *.DFM}
-
- {-------------------------------------------------------------------------------}
- {Load Image into background Picbuf control called 'PicbufOriginal'. When this
- occurs a 'Changeevent' is triggered in that buffer. Use that event to copy the
- Image to the 'PicbufVisible' Control. This means we are working with a Copy of
- the Image - See Below for Change Event}
- procedure TForm1.LoadImageClick(Sender: TObject);
- begin
- {Use CommonDialog Box to get FileName}
- if OpenDialog.Execute then
- begin
- {Set FileName}
- PicbufOriginal.FileName:=OpenDialog.FileName;
- {Call Load Method}
- PicbufOriginal.Load;
- end;
- end;
-
-
- {-------------------------------------------------------------------------------}
- {Copy original Image to visible Image using DIB's. The Image is copied to the
- 'PicbufVisible' when you load an Image or Change the Image within the Original
- Picbuf - Change Event}
- procedure TForm1.PicbufOriginalChange(Sender: TObject);
- var
- Hdib:Integer;{Store the Dib}
- begin
- hDIB := PicbufOriginal.DuplicateDib(0); {Copy the Original Image - Pass O}
- PicbufVisible.ImportDib(hDIB, False); {Display Copied Image - Pass False}
- end;
-
-
- {-------------------------------------------------------------------------------}
- {Save 'PicbufVisible' Picbuf Image - Reuse CommonDialog Control}
- procedure TForm1.SaveImageAsClick(Sender: TObject);
- begin
- if OpenDialog.Execute then
- begin
- PicbufVisible.Filename:=OpenDialog.filename; {Set FileName}
- if ValidFormat(PicbufVisible.Filename)then{See Below - Is File extension Valid}
- PicbufVisible.Store {Call Save Method of Picbuf}
- else
- MessageDlg('Your File Extension is Not Valid.', mtInformation, [mbOk], 0);
- end;
- end;
-
- {-------------------------------------------------------------------------------}
- {Undo any changes. We Simply recall the 'ChangeEvent' of the 'PicbufOriginal'
- Picbuf. This causes the original Image to be copied to the 'PicbufVisible' picbuf
- control}
- procedure TForm1.UndoClick(Sender: TObject);
- begin
- PicbufOriginalChange(Sender); {Recall event}
- end;
-
- {-------------------------------------------------------------------------------}
- {Apply desired function to visible Image. When the user clicks the Process Button
- a click event is triggered. We can reference each button within the 'RadioButton'
- Group using their ItemIndex - top Button is GrayScale Index No 0, Next Button is
- Index 1 and so on. Simply use a 'SelectCase' based on their ItemIndex values - the
- ItemIndex reflects which button is checked.}
- procedure TForm1.ProcessImageClick(Sender: TObject);
- begin
- case RadioGroup.ItemIndex of {Radio Button Control}
- 0:PicbufVisible.GrayScale; {Gray Button}
- 1:PicbufVisible.Negate; {Negate}
- 2:PicbufVisible.Mirror(-1, 0);{Must Pass -1 for True and 0 for False Mirror}
- 3:PicbufVisible.Mirror(0, -1);{Must Pass -1 for True and 0 for False Mirror} {Mirror}
- 4:{Rotate Image Based on Edit Box Value}
- begin
- PicbufVisible.Rotate(Angle.Value,RGB(255,0,0)) {Rotate Image}
- end;
- end;
- end;
-
- {-------------------------------------------------------------------------------}
- {Show / Hide Rotate Option Edit Box - Use ItemIndex. If the ItemIndex is not 4
- then the user is not wanting rotation so hide the Input box. 'Click Event' from
- RadioGroup.}
- procedure TForm1.RadioGroupClick(Sender: TObject);
- begin
- if RadioGroup.ItemIndex = 4 then
- Angle.Visible:= True {Hide}
- else {Show}
- Angle.Visible:=False;
- end;
-
-
- {-------------------------------------------------------------------------------}
- {Close All Forms}
- procedure TForm1.ExitClick(Sender: TObject);
- begin
- Halt;
- end;
-
-
- {-------------------------------------------------------------------------------}
- {Any Defaults on Creation - Not Part of MAI Demo}
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- Application.HintPause:=10;
- Application.HintColor:=clAqua;
- end;
-
- {-------------------------------------------------------------------------------}
- { This function simply checks to see if any one of the listed ImageKnife formats
- exist in the filename passed to the function. If it does then the function
- evaluates to true - Note this is the RESULT of the function}
- function ValidFormat(FileName:String):Boolean;
- Var
- Temp:String;
- begin
- Temp := UpperCase(Filename);{Convert FileName to Upper Case}
- Result:=False;{Default result if no recognised match is found - *.*}
- if Pos('.TIF', Temp ) > 0 then Result:= True;
- if Pos('.TGA', Temp ) > 0 then Result:= True;
- if Pos('.BMP', Temp ) > 0 then Result:= True;
- if Pos('.GIF', Temp ) > 0 then Result:= True;
- if Pos('.DIB', Temp ) > 0 then Result:= True;
- if Pos('.PCX', Temp ) > 0 then Result:= True;
- if Pos('.JPG', Temp ) > 0 then Result:= True;
- if Pos('.MSP', Temp ) > 0 then Result:= True;
- if Pos('.FIF', Temp ) > 0 then Result:= True;
- if Pos('.PNG', Temp ) > 0 then Result:= True;
- end;
-
- procedure TForm1.FormActivate(Sender: TObject);
- begin
- PicBufVisible.ScrollBars := SB_Both;
- PicBufOriginal.Filename := '..\images\twirl1.jpg';
- PicBufOriginal.Load;
- end;
-
- end.
-