source: trunk/Packages/bgracontrols/testbgraimagemanipulation/unitbgraimagemanipulationdemo.pas

Last change on this file was 2, checked in by chronos, 5 years ago
File size: 5.3 KB
Line 
1unit UnitBGRAImageManipulationDemo;
2
3{ ============================================================================
4 BGRAImageManipulation Demon Unit
5
6 Copyright (C) 2011 - Emerson Cavalcanti
7
8 This program is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Library General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or (at your
11 option) any later version.
12
13 This program is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
16 for more details.
17
18 You should have received a copy of the GNU Library General Public License
19 along with this library; if not, write to the Free Software Foundation,
20 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21
22 ============================================================================
23 Description:
24
25 TFormBGRAImageManipulationDemo is a sample form to use the component
26 TBGRAImageManipulation.
27
28 ============================================================================
29 History:
30
31 2011-05-06 - Emerson Cavalcanti
32 - Initial version
33
34 2011-06-01 - Emerson Cavalcanti
35 - Relayout of form.
36 - Add control to toggle the option 'Keep Aspect Ratio' in
37 component
38
39 2011-06-18 - Emerson Cavalcanti
40 - Relayout of form for expand component on resize.
41 - Add control to rotate image
42
43 ============================================================================
44}
45
46{$mode objfpc}{$H+}
47
48interface
49
50uses
51 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
52 Buttons, ExtDlgs, ComCtrls, ExtCtrls, BGRAImageManipulation, BGRABitmap,
53 BGRABitmapTypes, BGRAPanel, BGRAButton{, BGRATrackBar};
54
55type
56
57 { TFormBGRAImageManipulationDemo }
58
59 TFormBGRAImageManipulationDemo = class(TForm)
60 Background: TBGRAPanel;
61 btnShape: TBGRAButton;
62 btnOpenPicture: TBGRAButton;
63 BGRAImageManipulation: TBGRAImageManipulation;
64 btnGetAspectRatioFromImage: TBGRAButton;
65 btnSavePicture: TBGRAButton;
66 btnSetAspectRatio: TBGRAButton;
67 btnRotateLeft: TBGRAButton;
68 btnRotateRight: TBGRAButton;
69 edAspectRatio: TEdit;
70 KeepAspectRatio: TCheckBox;
71 lbAspectRatio: TLabel;
72 lbOptions: TLabel;
73 lbCompression: TLabel;
74 OpenPictureDialog: TOpenPictureDialog;
75 SavePictureDialog: TSavePictureDialog;
76 RateCompression: TTrackBar;
77 procedure btnGetAspectRatioFromImageClick(Sender: TObject);
78 procedure btnOpenPictureClick(Sender: TObject);
79 procedure btnRotateLeftClick(Sender: TObject);
80 procedure btnRotateRightClick(Sender: TObject);
81 procedure btnSavePictureClick(Sender: TObject);
82 procedure btnSetAspectRatioClick(Sender: TObject);
83 procedure KeepAspectRatioClick(Sender: TObject);
84 private
85 { private declarations }
86 public
87 { public declarations }
88 end;
89
90var
91 FormBGRAImageManipulationDemo: TFormBGRAImageManipulationDemo;
92
93implementation
94
95{$R *.lfm}
96
97{ TFormBGRAImageManipulationDemo }
98
99procedure TFormBGRAImageManipulationDemo.btnOpenPictureClick(Sender: TObject);
100var
101 Bitmap: TBGRABitmap;
102begin
103 // To put a new image in the component, you will simply need execute open
104 // picture dialog to locate an image...
105 if OpenPictureDialog.Execute then
106 begin
107 // ...and create a new TBGRABitmap and load to it
108 Bitmap := TBGRABitmap.Create;
109 Bitmap.LoadFromFile(OpenPictureDialog.FileName);
110 // Finally, associate the image into component
111 BGRAImageManipulation.Bitmap := Bitmap;
112 Bitmap.Free;
113 end;
114end;
115
116procedure TFormBGRAImageManipulationDemo.btnRotateLeftClick(Sender: TObject);
117begin
118 BGRAImageManipulation.rotateLeft;
119end;
120
121procedure TFormBGRAImageManipulationDemo.btnRotateRightClick(Sender: TObject);
122begin
123 BGRAImageManipulation.rotateRight;
124end;
125
126procedure TFormBGRAImageManipulationDemo.btnGetAspectRatioFromImageClick(
127 Sender: TObject);
128begin
129 if not (BGRAImageManipulation.Empty) then
130 begin
131 edAspectRatio.Text := BGRAImageManipulation.getAspectRatioFromImage(
132 BGRAImageManipulation.Bitmap);
133 end;
134end;
135
136procedure TFormBGRAImageManipulationDemo.btnSavePictureClick(Sender: TObject);
137var
138 JpegImage: TJpegImage;
139begin
140 // This example save image compress in JPEG format
141
142 // Execute our Save Picture Dialog
143 SavePictureDialog.Filter := 'JPEG Image File (*.jpg, *.jpeg)';
144 if SavePictureDialog.Execute then
145 begin
146 try
147 // Compress
148 JpegImage := TJpegImage.Create;
149 JpegImage.Assign(BGRAImageManipulation.getBitmap);
150 JpegImage.CompressionQuality := RateCompression.Position;
151
152 // And save to file
153 JpegImage.SaveToFile(SavePictureDialog.FileName);
154 finally
155 JpegImage.Free;
156 end;
157 end;
158end;
159
160procedure TFormBGRAImageManipulationDemo.btnSetAspectRatioClick(Sender: TObject);
161begin
162 try
163 BGRAImageManipulation.AspectRatio := edAspectRatio.Text;
164 except
165 on E: Exception do
166 begin
167 ShowMessage('This aspect ratio is invalid');
168 end;
169 end;
170end;
171
172procedure TFormBGRAImageManipulationDemo.KeepAspectRatioClick(Sender: TObject);
173begin
174 BGRAImageManipulation.KeepAspectRatio := KeepAspectRatio.Checked;
175 edAspectRatio.Enabled := KeepAspectRatio.Checked;
176 btnSetAspectRatio.Enabled := KeepAspectRatio.Checked;
177end;
178
179end.
Note: See TracBrowser for help on using the repository browser.