diff options
author | jp anghel <jp.anghel@bbox.fr> | 2010-05-14 16:10:00 +0200 |
---|---|---|
committer | Graeme Geldenhuys <graeme@mastermaths.co.za> | 2010-05-14 16:10:00 +0200 |
commit | 59a25d4316391ddec1146ee5f507879b2785c38e (patch) | |
tree | 988e37690035c215cce1cabd00c93dce06c53dd8 /examples | |
parent | 31ba3e71d1d903eb953738acca98c14d4419f929 (diff) | |
download | fpGUI-59a25d4316391ddec1146ee5f507879b2785c38e.tar.xz |
JPEG image loading support
Diffstat (limited to 'examples')
-rw-r--r-- | examples/gui/imgtest_jpeg/jpeg.lpi | 73 | ||||
-rw-r--r-- | examples/gui/imgtest_jpeg/jpeg.lpr | 24 | ||||
-rw-r--r-- | examples/gui/imgtest_jpeg/main.pas | 206 | ||||
-rw-r--r-- | examples/gui/imgtest_jpeg/poppy.jpg | bin | 0 -> 26709 bytes | |||
-rw-r--r-- | examples/gui/imgtest_jpeg/poppygray.jpg | bin | 0 -> 22884 bytes | |||
-rw-r--r-- | examples/gui/imgtest_jpeg/poppyprogressif.jpg | bin | 0 -> 25271 bytes | |||
-rw-r--r-- | examples/gui/imgtest_jpeg/units/.gitignore | 1 |
7 files changed, 304 insertions, 0 deletions
diff --git a/examples/gui/imgtest_jpeg/jpeg.lpi b/examples/gui/imgtest_jpeg/jpeg.lpi new file mode 100644 index 00000000..6b0fc630 --- /dev/null +++ b/examples/gui/imgtest_jpeg/jpeg.lpi @@ -0,0 +1,73 @@ +<?xml version="1.0"?> +<CONFIG> + <ProjectOptions> + <Version Value="7"/> + <General> + <Flags> + <SaveOnlyProjectUnits Value="True"/> + <MainUnitHasCreateFormStatements Value="False"/> + <MainUnitHasTitleStatement Value="False"/> + <UseDefaultCompilerOptions Value="True"/> + </Flags> + <SessionStorage Value="InProjectDir"/> + <MainUnit Value="0"/> + <TargetFileExt Value=""/> + <UseAppBundle Value="False"/> + <ResourceType Value="res"/> + </General> + <VersionInfo> + <Language Value=""/> + <CharSet Value=""/> + <StringTable Comments="" CompanyName="" FileDescription="" FileVersion="" InternalName="" LegalCopyright="" LegalTrademarks="" OriginalFilename="" ProductName="" ProductVersion=""/> + </VersionInfo> + <PublishOptions> + <Version Value="2"/> + <IgnoreBinaries Value="False"/> + <IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/> + <ExcludeFileFilter Value="*.(bak|ppu|ppw|o|so);*~;backup"/> + </PublishOptions> + <RunParams> + <local> + <FormatVersion Value="1"/> + <LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/> + </local> + </RunParams> + <RequiredPackages Count="1"> + <Item1> + <PackageName Value="fpgui_toolkit"/> + </Item1> + </RequiredPackages> + <Units Count="2"> + <Unit0> + <Filename Value="jpeg.lpr"/> + <IsPartOfProject Value="True"/> + </Unit0> + <Unit1> + <Filename Value="main.pas"/> + <IsPartOfProject Value="True"/> + <UnitName Value="main"/> + </Unit1> + </Units> + </ProjectOptions> + <CompilerOptions> + <Version Value="8"/> + <SearchPaths> + <UnitOutputDirectory Value="units"/> + </SearchPaths> + <Parsing> + <SyntaxOptions> + <UseAnsiStrings Value="True"/> + </SyntaxOptions> + </Parsing> + <Other> + <CompilerPath Value="$(CompPath)"/> + </Other> + </CompilerOptions> + <Debugging> + <Exceptions Count="1"> + <Item1> + <Name Value="EDatabaseError"/> + </Item1> + </Exceptions> + </Debugging> +</CONFIG> diff --git a/examples/gui/imgtest_jpeg/jpeg.lpr b/examples/gui/imgtest_jpeg/jpeg.lpr new file mode 100644 index 00000000..00c5fbd5 --- /dev/null +++ b/examples/gui/imgtest_jpeg/jpeg.lpr @@ -0,0 +1,24 @@ +program jpeg; + +{$mode objfpc}{$H+} + +uses + {$IFDEF UNIX}{$IFDEF UseCThreads} + cthreads, + {$ENDIF}{$ENDIF} + Classes, fpg_main, main; + +procedure MainProc; +begin + fpgApplication.Initialize; + frmMain := TfrmMain.Create(nil); + frmMain.Show; + fpgApplication.Run; + frmMain.Free; +end; + +begin + MainProc; +end. + + diff --git a/examples/gui/imgtest_jpeg/main.pas b/examples/gui/imgtest_jpeg/main.pas new file mode 100644 index 00000000..3525045e --- /dev/null +++ b/examples/gui/imgtest_jpeg/main.pas @@ -0,0 +1,206 @@ +unit main; + +{$mode objfpc}{$H+} + +interface + +uses + SysUtils, Classes, fpg_base, fpg_main, fpg_form, fpg_panel, fpg_button, + fpg_radiobutton, fpg_dialogs, fpg_imgfmt_jpg; + +type + + TfrmMain = class(TfpgForm) + private + {@VFD_HEAD_BEGIN: frmMain} + Panel1: TfpgPanel; + RadioButton1: TfpgRadioButton; + RadioButton2: TfpgRadioButton; + RadioButton3: TfpgRadioButton; + RadioButton4: TfpgRadioButton; + Button1: TfpgButton; + Button2: TfpgButton; + {@VFD_HEAD_END: frmMain} + FImage: TfpgImage; + FImageName: string; + SizeSelect: integer; + procedure Btn1Click(Sender: TObject); + procedure Btn2Click(Sender: TObject); + procedure rbChanged(Sender: TObject); + procedure FormPaint(Sender: TObject); + procedure LoadImage; + public + constructor Create(AOwner: TComponent); override; + destructor Destroy; override; + procedure AfterCreate; override; + end; + +{@VFD_NEWFORM_DECL} + var frmMain: TfrmMain; + +implementation + +{@VFD_NEWFORM_IMPL} + +procedure TfrmMain.AfterCreate; +begin + {%region 'Auto-generated GUI code' -fold} + {@VFD_BODY_BEGIN: frmMain} + Name := 'frmMain'; + SetPosition(321, 289, 330, 380); + WindowTitle := 'JPEG Image Test'; + WindowPosition := wpOneThirdDown; + Hint := ''; + + Panel1 := TfpgPanel.Create(self); + with Panel1 do + begin + Name := 'Panel1'; + SetPosition(16, 260, 96, 112); + FontDesc := '#Label1'; + Hint := ''; + Text := ''; + end; + + RadioButton1 := TfpgRadioButton.Create(Panel1); + with RadioButton1 do + begin + Name := 'RadioButton1'; + SetPosition(8, 8, 80, 20); + Checked := True; + FontDesc := '#Label1'; + GroupIndex := 0; + Hint := ''; + TabOrder := 1; + Text := 'Full size'; + Tag:=1; + OnChange := @rbChanged; + end; + + RadioButton2 := TfpgRadioButton.Create(Panel1); + with RadioButton2 do + begin + Name := 'RadioButton2'; + SetPosition(8, 32, 72, 20); + FontDesc := '#Label1'; + GroupIndex := 0; + Hint := ''; + TabOrder := 1; + Text := '1/2 size'; + Tag:=2; + OnChange := @rbChanged; + end; + + RadioButton3 := TfpgRadioButton.Create(Panel1); + with RadioButton3 do + begin + Name := 'RadioButton3'; + SetPosition(8, 56, 72, 20); + FontDesc := '#Label1'; + GroupIndex := 0; + Hint := ''; + TabOrder := 2; + Text := '1/4 size'; + Tag:=3; + OnChange := @rbChanged; + end; + + RadioButton4 := TfpgRadioButton.Create(Panel1); + with RadioButton4 do + begin + Name := 'RadioButton4'; + SetPosition(8, 80, 72, 20); + FontDesc := '#Label1'; + GroupIndex := 0; + Hint := ''; + TabOrder := 3; + Text := '1/8 size'; + Tag:=4; + OnChange := @rbChanged; + end; + + Button1 := TfpgButton.Create(self); + with Button1 do + begin + Name := 'Button1'; + SetPosition(216, 260, 80, 24); + Text := 'Open'; + FontDesc := '#Label1'; + Hint := ''; + ImageName := ''; + TabOrder := 2; + OnClick:=@Btn1Click; + end; + + Button2 := TfpgButton.Create(self); + with Button2 do + begin + Name := 'Button2'; + SetPosition(216, 304, 80, 24); + Text := 'Close'; + FontDesc := '#Label1'; + Hint := ''; + ImageName := ''; + TabOrder := 3; + OnClick:=@Btn2Click; + end; + + {@VFD_BODY_END: frmMain} + {%endregion} +end; + +procedure TfrmMain.LoadImage; +begin + WindowTitle := FImageName; + FImage := LoadImage_JPG(FImageName, SizeSelect); + RePaint; +end; + +constructor TfrmMain.Create(AOwner: TComponent); +begin + inherited Create(AOwner); + OnPaint := @FormPaint; + SizeSelect := 1; // full size by default +end; + +destructor TfrmMain.Destroy; +begin + FImage.Free; + inherited Destroy; +end; + +procedure TfrmMain.Btn1Click(Sender: TObject); +var + dlg: TfpgFileDialog; +begin + dlg := TfpgFileDialog.Create(nil); + try + dlg.Filter := 'JPEG Image (*.jpg)|*.jpg'; + if dlg.RunOpenFile then + begin + FImageName:= dlg.FileName; + end; + finally + dlg.Free; + end; + LoadImage; +end; + +procedure TfrmMain.Btn2Click(Sender: TObject); +begin + Close; +end; + +procedure TfrmMain.FormPaint(Sender: TObject); +begin + Canvas.DrawImage(0, 0, FImage); +end; + +procedure TfrmMain.rbChanged(Sender: TObject); +begin + if Sender is TfpgRadioButton then + SizeSelect := TfpgRadioButton(Sender).Tag; + LoadImage; +end; + +end. diff --git a/examples/gui/imgtest_jpeg/poppy.jpg b/examples/gui/imgtest_jpeg/poppy.jpg Binary files differnew file mode 100644 index 00000000..367efe30 --- /dev/null +++ b/examples/gui/imgtest_jpeg/poppy.jpg diff --git a/examples/gui/imgtest_jpeg/poppygray.jpg b/examples/gui/imgtest_jpeg/poppygray.jpg Binary files differnew file mode 100644 index 00000000..0a9b4d20 --- /dev/null +++ b/examples/gui/imgtest_jpeg/poppygray.jpg diff --git a/examples/gui/imgtest_jpeg/poppyprogressif.jpg b/examples/gui/imgtest_jpeg/poppyprogressif.jpg Binary files differnew file mode 100644 index 00000000..2147ed64 --- /dev/null +++ b/examples/gui/imgtest_jpeg/poppyprogressif.jpg diff --git a/examples/gui/imgtest_jpeg/units/.gitignore b/examples/gui/imgtest_jpeg/units/.gitignore new file mode 100644 index 00000000..f59ec20a --- /dev/null +++ b/examples/gui/imgtest_jpeg/units/.gitignore @@ -0,0 +1 @@ +*
\ No newline at end of file |