home *** CD-ROM | disk | FTP | other *** search
- { Project Assign.DPR Delphi 2.0 Demos
-
- Description:- Assign.Dpr Project:-
-
- Demonstrates the use of:
-
- 1) 'AssignMode'
- 2) 'ResizeMode'
- 3) 'Assign' Method
-
- 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 UAssign;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- Menus, ExtCtrls, Buttons, OleCtrls, ImageKnife32, StdCtrls;
-
- type
- TMasterform = class(TForm)
- MainMenu: TMainMenu;
- File_Menu: TMenuItem;
- File_Menu_LoadAssignImage: TMenuItem;
- File_Menu_LoadResizeImage: TMenuItem;
- N1: TMenuItem;
- File_Menu_ClearallImages: TMenuItem;
- N2: TMenuItem;
- File_Menu_Exit: TMenuItem;
- Bevel1: TBevel;
- Label1: TLabel;
- Label2: TLabel;
- AssignMode: TComboBox;
- ResizeMode: TComboBox;
- PicbufSrc: TPicbuf;
- PicbufDest: TPicbuf;
- SrcToDestAssign: TSpeedButton;
- DestToSrcAssign: TSpeedButton;
- Bevel2: TBevel;
- Bevel3: TBevel;
- GroupBox1: TGroupBox;
- GroupBox2: TGroupBox;
- SrcFull: TRadioButton;
- SrcSel: TRadioButton;
- DestFull: TRadioButton;
- DestSel: TRadioButton;
- Reset: TSpeedButton;
- FileOpenDialog: TOpenDialog;
- DitherSrctoDest: TSpeedButton;
- DitherDesttoSrc: TSpeedButton;
- procedure File_Menu_LoadAssignImageClick(Sender: TObject);
- procedure File_Menu_LoadResizeImageClick(Sender: TObject);
- procedure ResetClick(Sender: TObject);
- procedure File_Menu_ClearallImagesClick(Sender: TObject);
- procedure File_Menu_ExitClick(Sender: TObject);
- procedure SrcToDestAssignClick(Sender: TObject);
- procedure DestToSrcAssignClick(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure AssignModeClick(Sender: TObject);
- procedure ResizeModeClick(Sender: TObject);
- procedure DitherSrctoDestClick(Sender: TObject);
- procedure DitherDesttoSrcClick(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
- var
- Masterform: TMasterform;
-
- {Additional function added for Demo Only - See Below for function}
- function GetImageLocation:String;
-
- implementation
-
- {$R *.DFM}
-
- {-------------------------------------------------------------------------------)
- {File Menu Item - Click Event}
- {'Source Picbuf' - Load a File using a Common Dialogue Component}
- procedure TMasterform.File_Menu_LoadAssignImageClick(Sender: TObject);
- begin
- {Display Dialogue - Has the User Selected OK and a Valid File extension}
- if FileOpenDialog.Execute then
- begin
- {Reference Common Dialogue - We can then refer just to its properties}
- with FileOpenDialog do
- PicbufSrc.Filename:= Filename; {Set the Name to the Dialogue Filename}
- PicbufSrc.Load; {Load The Image}
- end;
- end;
-
- {-------------------------------------------------------------------------------)
- {File Menu Item - Click Event}
- {'Destination Picbuf' - Load a File using a Common Dialogue Component}
- procedure TMasterform.File_Menu_LoadResizeImageClick(Sender: TObject);
- begin
- {Has the User Selected OK and a Valid File extension}
- if FileOpenDialog.Execute then
- begin
- {Reference Common Dialogue - We can then refer just to its properties}
- with FileOpenDialog do
- PicbufDest.Filename:= Filename;
- PicbufDest.Load; {Load The Image}
- end;
- end;
-
- {-------------------------------------------------------------------------------)
- {Reset Button - Click Event}
- {Reload the Source and Destination Images}
- procedure TMasterform.ResetClick(Sender: TObject);
- begin
- PicbufSrc.Clear; {Standard Call}
- PicbufDest.Clear; {Standard Call}
- PicbufSrc.Load; {Force a Load using last set filename}
- PicbufDest.Load; {Force a Load using last set filename}
- end;
-
- {-------------------------------------------------------------------------------)
- {File Menu Item - Click Event}
- {Clear the Images}
- procedure TMasterform.File_Menu_ClearallImagesClick(Sender: TObject);
- begin
- PicbufSrc.Clear; {Standard Call}
- PicbufDest.Clear; {Standard Call}
- end;
-
- {-------------------------------------------------------------------------------)
- {File Menu Item - Click Event}
- {Exit the Program}
- procedure TMasterform.File_Menu_ExitClick(Sender: TObject);
- begin
- Halt; {Terminates all objects unconditionally}
- end;
-
- {-------------------------------------------------------------------------------)
- {Transfer Button:-
- Transfer the 'Source' buffer to the 'Destination' buffer.
- Use the 'Assign' Method, and use the 'Option' buttons as the True/False Flags
- for the two selection 'Parameters' of the 'Assign' Method. For 8 Bit Images
- dither the Images to the Same Palette}
- procedure TMasterform.SrcToDestAssignClick(Sender: TObject);
- begin
- PicbufDest.Assign(DestSel.Checked, PicbufSrc.OLEOBJECT, SrcSel.Checked);
- end;
-
- {-------------------------------------------------------------------------------)
- {Transfer Button:-
- Transfer 'Destination' buffer to the 'Source' Buffer.
- Use the 'Assign' Method, and use the 'Option' buttons as the True/False Flags
- for the two selection 'Parameters' of the 'Assign' Method. For 8 Bit Images
- dither the Images to the Same Palette}
- procedure TMasterform.DestToSrcAssignClick(Sender: TObject);
- begin
- PicbufSrc.Assign(SrcSel.Checked, PicbufDest.OLEOBJECT,DestSel.Checked);
- end;
-
- {-------------------------------------------------------------------------------)
- {Form Creation - Set Defaults:-
- Set up all defaults required using the 'Masterform' 'FormCreate' Event.
-
- Note:- All string Items ie Captions are added at design time using Delphi to any
- controls requiring them. The 'Combo Boxes' giving the user the ability to set the
- required 'Resize' and 'Assign' modes are filled in using the controls built in text
- string editor. All we do at load time is to tell the control which item to set
- as a starting value - default value.}
- procedure TMasterform.FormCreate(Sender: TObject);
- begin
- {Set Project Properties - not part of MAI demo}
- Application.HintPause := 10; {Hint Pause}
- Application.HintColor := clAqua; {Hint Colour}
-
- {Set Combo Boxes to Item Index 0}
- AssignMode.ItemIndex:=0; {Total Replacement}
- ResizeMode.ItemIndex:=0; {Pixel Deletion}
-
- {Demo Default Images are loaded if they exist)
- {Set Image Defaults - Uses GetImageLocation function - this function is provided
- so the demo program finds default test Images}
- PicbufSrc.Filename:=GetImageLocation + 'images\leaves8.pcx';
- PicbufDest.Filename:=GetImageLocation + 'images\marybeth.tif';
-
- {Load Default Source Image if they exist}
- if FileExists(GetImageLocation + 'images\leaves8.pcx') then
- PicbufSrc.Load
- else
- MessageDlg('Cannot find Sample file [\Images\Leaves8.PCX].' +
- ' Users should manually load this Image into the Source Picture.', mtInformation,
- [mbOk], 0);
-
- {Load Default Destination Image if they exist}
- if FileExists(GetImageLocation + 'images\marybeth.tif') then
- PicbufDest.Load
- else
- MessageDlg('Cannot find Sample file [\Images\Marybeth.TIF].' +
- ' Users should manually load this Image into the Source Picture.', mtInformation,
- [mbOk], 0);
-
- {Set default selection areas for both source and destination picbuf's}
- PicbufSrc.SelectWidth:=100;
- PicbufSrc.SelectHeight:=100;
- PicbufDest.SelectWidth:=100;
- PicbufDest.SelectHeight:=100;
- end;
-
- {-------------------------------------------------------------------------------)
- {Set 'AssignMode' of both picture buffers using 'ComboBox' click events:-
-
- DELPHI USERS NOTE:- Without Pre-Defining 'AssignModes' as 'Constants' we must refer
- to each mode/property as an 'Integer'. If the user wishes he can Ccreate constants
- for each function so AssignMode 'AMTotal' is the same as 'AssignMode' Value of 0. So
- if you wish to set a property by using 'Constants' you must predefine a constant eg:-
-
- Const
- AMMode = 0; You can then use 'AMMode' instead of '0'
-
- From then on you can use 'AMMode' to set a property. Use Object Inspector to see the
- Integer values assigned to each property. Users note that this method does allow you
- to use 'String' expressions to set properties, however, if you stick to using integer
- values it means you can greatly simplify the setting of properties. See the following
- routine. Since the AssignMode is expecting a value of 0 to 3, this matches the index
- values returned by a combobox so you can use the 'itemindex' to directly set the
- value - It simplifies the sub down to a couple of lines. Note:- When you are adding
- the Items [Strings] to the ComboBox make sure you put them in the correct order so
- the correct index value is returned for the correct function - use this order:-
-
- 0 - Total Replacement [Item Index 0]
- 1 - Union Composite [Item Index 1]
- 2 - Intersection Composite [Item Index 2]
- 3 - Resize Composite [Item Index 3] }
-
- procedure TMasterform.AssignModeClick(Sender: TObject);
- begin
- {Refer to Sending Combobox - ie 'AssignMode'}
- with AssignMode do
- begin
- {Use 'ItemIndex' that is part of the 'AssignMode' Combo Box}
- PicbufSrc.AssignMode:=ItemIndex; {Set Mode of Source Picbuf}
- PicbufDest.AssignMode:=ItemIndex; {Set Mode of Destination Picbuf}
- end;
- end;
-
- {-------------------------------------------------------------------------------)
- {Set 'ResizeMode' of both Picture buffers:-
-
- Index Values and Item String List for ComboBox:-
-
- 0 - Pixel Deletion/Replication, Fixed Aspect
- 1 - Pixel Deletion/Replication, Variable Aspect
- 2 - Resampling, Fixed Aspect
- 3 - Resampling, Variable Aspect
-
- Please refer to notes above.}
- procedure TMasterform.ResizeModeClick(Sender: TObject);
- begin
- {Refer to Sending Combobox - 'ResizeMode'}
- with ResizeMode do
- begin
- PicbufSrc.ResizeMode:=ItemIndex; {Set Source Mode}
- PicbufDest.ResizeMode:=ItemIndex; {Set Destination Mode}
- end;
- end;
-
- {-------------------------------------------------------------------------------}
- {Map Source Image to Destination}
- procedure TMasterform.DitherSrctoDestClick(Sender: TObject);
- begin
- Picbufsrc.DitherPal(Picbufdest.OLEOBJECT);
- end;
-
- {-------------------------------------------------------------------------------}
- {Map Destination to Source}
- procedure TMasterform.DitherDesttoSrcClick(Sender: TObject);
- begin
- PicbufDest.DitherPal(PicbufSrc.OLEOBJECT);
- end;
-
-
- {-------------------------------------------------------------------------------}
- {Get path of default files:-
- Basically the function gets the path name of the EXE location, strips of the last
- directory, ready for use - only applicable to this Demo}
- function GetImageLocation:String;
- Var
- Temp:String;
- DelphiLocation:Integer;
- begin
- Temp := ExtractFileDir(Application.exename); {Get full path of EXE}
- Temp := UpperCase(Temp); {Make Sure it is upper Case}
- DelphiLocation := Pos('\DELPHI2',Temp);
- Delete(Temp,DelphiLocation,length('\DELPHI2')); {Strip of last Directory}
- Result:=Temp + '\'; {Add the Missing '\'}
- end;
-
-
-
- end.
-