1 | unit 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 |
|
---|
48 | interface
|
---|
49 |
|
---|
50 | uses
|
---|
51 | Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
|
---|
52 | Buttons, ExtDlgs, ComCtrls, ExtCtrls, BGRAImageManipulation, BGRABitmap,
|
---|
53 | BGRABitmapTypes, BGRAPanel, BGRAButton{, BGRATrackBar};
|
---|
54 |
|
---|
55 | type
|
---|
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 |
|
---|
90 | var
|
---|
91 | FormBGRAImageManipulationDemo: TFormBGRAImageManipulationDemo;
|
---|
92 |
|
---|
93 | implementation
|
---|
94 |
|
---|
95 | {$R *.lfm}
|
---|
96 |
|
---|
97 | { TFormBGRAImageManipulationDemo }
|
---|
98 |
|
---|
99 | procedure TFormBGRAImageManipulationDemo.btnOpenPictureClick(Sender: TObject);
|
---|
100 | var
|
---|
101 | Bitmap: TBGRABitmap;
|
---|
102 | begin
|
---|
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;
|
---|
114 | end;
|
---|
115 |
|
---|
116 | procedure TFormBGRAImageManipulationDemo.btnRotateLeftClick(Sender: TObject);
|
---|
117 | begin
|
---|
118 | BGRAImageManipulation.rotateLeft;
|
---|
119 | end;
|
---|
120 |
|
---|
121 | procedure TFormBGRAImageManipulationDemo.btnRotateRightClick(Sender: TObject);
|
---|
122 | begin
|
---|
123 | BGRAImageManipulation.rotateRight;
|
---|
124 | end;
|
---|
125 |
|
---|
126 | procedure TFormBGRAImageManipulationDemo.btnGetAspectRatioFromImageClick(
|
---|
127 | Sender: TObject);
|
---|
128 | begin
|
---|
129 | if not (BGRAImageManipulation.Empty) then
|
---|
130 | begin
|
---|
131 | edAspectRatio.Text := BGRAImageManipulation.getAspectRatioFromImage(
|
---|
132 | BGRAImageManipulation.Bitmap);
|
---|
133 | end;
|
---|
134 | end;
|
---|
135 |
|
---|
136 | procedure TFormBGRAImageManipulationDemo.btnSavePictureClick(Sender: TObject);
|
---|
137 | var
|
---|
138 | JpegImage: TJpegImage;
|
---|
139 | begin
|
---|
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;
|
---|
158 | end;
|
---|
159 |
|
---|
160 | procedure TFormBGRAImageManipulationDemo.btnSetAspectRatioClick(Sender: TObject);
|
---|
161 | begin
|
---|
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;
|
---|
170 | end;
|
---|
171 |
|
---|
172 | procedure TFormBGRAImageManipulationDemo.KeepAspectRatioClick(Sender: TObject);
|
---|
173 | begin
|
---|
174 | BGRAImageManipulation.KeepAspectRatio := KeepAspectRatio.Checked;
|
---|
175 | edAspectRatio.Enabled := KeepAspectRatio.Checked;
|
---|
176 | btnSetAspectRatio.Enabled := KeepAspectRatio.Checked;
|
---|
177 | end;
|
---|
178 |
|
---|
179 | end.
|
---|