You've already forked lazarus-ccr
fpexif: Add Delphi examples
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7328 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -0,0 +1,15 @@
|
||||
program ExifSimpleDemo;
|
||||
|
||||
uses
|
||||
Forms,
|
||||
sdMain in 'sdMain.pas' {Form1};
|
||||
|
||||
{$R *.res}
|
||||
|
||||
begin
|
||||
Application.Initialize;
|
||||
Application.CreateForm(TMainForm, MainForm);
|
||||
MainForm.BeforeRun;
|
||||
Application.Run;
|
||||
end.
|
||||
|
@ -0,0 +1,139 @@
|
||||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<ProjectGuid>{927DB824-6C5B-4A5F-8555-627D51D654D3}</ProjectGuid>
|
||||
<MainSource>ExifSimpleDemo.dpr</MainSource>
|
||||
<Base>True</Base>
|
||||
<Config Condition="'$(Config)'==''">Debug</Config>
|
||||
<TargetedPlatforms>1</TargetedPlatforms>
|
||||
<AppType>Application</AppType>
|
||||
<FrameworkType>VCL</FrameworkType>
|
||||
<ProjectVersion>18.6</ProjectVersion>
|
||||
<Platform Condition="'$(Platform)'==''">Win32</Platform>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Config)'=='Base' or '$(Base)'!=''">
|
||||
<Base>true</Base>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="('$(Platform)'=='Win32' and '$(Base)'=='true') or '$(Base_Win32)'!=''">
|
||||
<Base_Win32>true</Base_Win32>
|
||||
<CfgParent>Base</CfgParent>
|
||||
<Base>true</Base>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="('$(Platform)'=='Win64' and '$(Base)'=='true') or '$(Base_Win64)'!=''">
|
||||
<Base_Win64>true</Base_Win64>
|
||||
<CfgParent>Base</CfgParent>
|
||||
<Base>true</Base>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Config)'=='Release' or '$(Cfg_1)'!=''">
|
||||
<Cfg_1>true</Cfg_1>
|
||||
<CfgParent>Base</CfgParent>
|
||||
<Base>true</Base>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="('$(Platform)'=='Win32' and '$(Cfg_1)'=='true') or '$(Cfg_1_Win32)'!=''">
|
||||
<Cfg_1_Win32>true</Cfg_1_Win32>
|
||||
<CfgParent>Cfg_1</CfgParent>
|
||||
<Cfg_1>true</Cfg_1>
|
||||
<Base>true</Base>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Config)'=='Debug' or '$(Cfg_2)'!=''">
|
||||
<Cfg_2>true</Cfg_2>
|
||||
<CfgParent>Base</CfgParent>
|
||||
<Base>true</Base>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="('$(Platform)'=='Win32' and '$(Cfg_2)'=='true') or '$(Cfg_2_Win32)'!=''">
|
||||
<Cfg_2_Win32>true</Cfg_2_Win32>
|
||||
<CfgParent>Cfg_2</CfgParent>
|
||||
<Cfg_2>true</Cfg_2>
|
||||
<Base>true</Base>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Base)'!=''">
|
||||
<DCC_E>false</DCC_E>
|
||||
<DCC_F>false</DCC_F>
|
||||
<DCC_K>false</DCC_K>
|
||||
<DCC_N>false</DCC_N>
|
||||
<DCC_S>false</DCC_S>
|
||||
<DCC_ImageBase>00400000</DCC_ImageBase>
|
||||
<SanitizedProjectName>ExifSimpleDemo</SanitizedProjectName>
|
||||
<DCC_Namespace>Vcl;Vcl.Imaging;Vcl.Touch;Vcl.Samples;Vcl.Shell;System;Xml;Data;Datasnap;Web;Soap;$(DCC_Namespace)</DCC_Namespace>
|
||||
<VerInfo_Locale>1031</VerInfo_Locale>
|
||||
<VerInfo_Keys>CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments=;CFBundleName=</VerInfo_Keys>
|
||||
<DCC_UnitSearchPath>..\..;$(DCC_UnitSearchPath)</DCC_UnitSearchPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Base_Win32)'!=''">
|
||||
<DCC_Namespace>Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace)</DCC_Namespace>
|
||||
<BT_BuildType>Debug</BT_BuildType>
|
||||
<VerInfo_IncludeVerInfo>true</VerInfo_IncludeVerInfo>
|
||||
<VerInfo_Keys>CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments=;ProgramID=com.embarcadero.$(MSBuildProjectName)</VerInfo_Keys>
|
||||
<VerInfo_Locale>1033</VerInfo_Locale>
|
||||
<Manifest_File>$(BDS)\bin\default_app.manifest</Manifest_File>
|
||||
<AppEnableRuntimeThemes>true</AppEnableRuntimeThemes>
|
||||
<UWP_DelphiLogo44>$(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_44.png</UWP_DelphiLogo44>
|
||||
<UWP_DelphiLogo150>$(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_150.png</UWP_DelphiLogo150>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Base_Win64)'!=''">
|
||||
<UWP_DelphiLogo44>$(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_44.png</UWP_DelphiLogo44>
|
||||
<UWP_DelphiLogo150>$(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_150.png</UWP_DelphiLogo150>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Cfg_1)'!=''">
|
||||
<DCC_Define>RELEASE;$(DCC_Define)</DCC_Define>
|
||||
<DCC_DebugInformation>0</DCC_DebugInformation>
|
||||
<DCC_LocalDebugSymbols>false</DCC_LocalDebugSymbols>
|
||||
<DCC_SymbolReferenceInfo>0</DCC_SymbolReferenceInfo>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Cfg_1_Win32)'!=''">
|
||||
<AppEnableRuntimeThemes>true</AppEnableRuntimeThemes>
|
||||
<AppDPIAwarenessMode>PerMonitorV2</AppDPIAwarenessMode>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Cfg_2)'!=''">
|
||||
<DCC_Define>DEBUG;$(DCC_Define)</DCC_Define>
|
||||
<DCC_Optimize>false</DCC_Optimize>
|
||||
<DCC_GenerateStackFrames>true</DCC_GenerateStackFrames>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Cfg_2_Win32)'!=''">
|
||||
<AppEnableRuntimeThemes>true</AppEnableRuntimeThemes>
|
||||
<AppDPIAwarenessMode>PerMonitorV2</AppDPIAwarenessMode>
|
||||
<VerInfo_IncludeVerInfo>true</VerInfo_IncludeVerInfo>
|
||||
<VerInfo_Locale>1033</VerInfo_Locale>
|
||||
<VerInfo_Keys>CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments=;ProgramID=com.embarcadero.$(MSBuildProjectName)</VerInfo_Keys>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<DelphiCompile Include="$(MainSource)">
|
||||
<MainSource>MainSource</MainSource>
|
||||
</DelphiCompile>
|
||||
<DCCReference Include="sdmain.pas">
|
||||
<Form>Form1</Form>
|
||||
</DCCReference>
|
||||
<BuildConfiguration Include="Debug">
|
||||
<Key>Cfg_2</Key>
|
||||
<CfgParent>Base</CfgParent>
|
||||
</BuildConfiguration>
|
||||
<BuildConfiguration Include="Base">
|
||||
<Key>Base</Key>
|
||||
</BuildConfiguration>
|
||||
<BuildConfiguration Include="Release">
|
||||
<Key>Cfg_1</Key>
|
||||
<CfgParent>Base</CfgParent>
|
||||
</BuildConfiguration>
|
||||
</ItemGroup>
|
||||
<ProjectExtensions>
|
||||
<Borland.Personality>Delphi.Personality.12</Borland.Personality>
|
||||
<Borland.ProjectType/>
|
||||
<BorlandProject>
|
||||
<Delphi.Personality>
|
||||
<Source>
|
||||
<Source Name="MainSource">ExifSimpleDemo.dpr</Source>
|
||||
</Source>
|
||||
<Excluded_Packages>
|
||||
<Excluded_Packages Name="$(BDSBIN)\dcloffice2k260.bpl">Microsoft Office 2000 Beispiele für gekapselte Komponenten für Automatisierungsserver</Excluded_Packages>
|
||||
<Excluded_Packages Name="$(BDSBIN)\dclofficexp260.bpl">Microsoft Office XP Beispiele für gekapselte Komponenten für Automation Server</Excluded_Packages>
|
||||
</Excluded_Packages>
|
||||
</Delphi.Personality>
|
||||
<Platforms>
|
||||
<Platform value="Win32">True</Platform>
|
||||
<Platform value="Win64">False</Platform>
|
||||
</Platforms>
|
||||
</BorlandProject>
|
||||
<ProjectFileVersion>12</ProjectFileVersion>
|
||||
</ProjectExtensions>
|
||||
<Import Project="$(BDS)\Bin\CodeGear.Delphi.Targets" Condition="Exists('$(BDS)\Bin\CodeGear.Delphi.Targets')"/>
|
||||
<Import Project="$(APPDATA)\Embarcadero\$(BDSAPPDATABASEDIR)\$(PRODUCTVERSION)\UserTools.proj" Condition="Exists('$(APPDATA)\Embarcadero\$(BDSAPPDATABASEDIR)\$(PRODUCTVERSION)\UserTools.proj')"/>
|
||||
</Project>
|
BIN
components/fpexif/delphi examples/simple_demo/ExifSimpleDemo.res
Normal file
BIN
components/fpexif/delphi examples/simple_demo/ExifSimpleDemo.res
Normal file
Binary file not shown.
186
components/fpexif/delphi examples/simple_demo/sdmain.dfm
Normal file
186
components/fpexif/delphi examples/simple_demo/sdmain.dfm
Normal file
@ -0,0 +1,186 @@
|
||||
object MainForm: TMainForm
|
||||
Left = 329
|
||||
Top = 131
|
||||
Caption = 'MainForm'
|
||||
ClientHeight = 477
|
||||
ClientWidth = 788
|
||||
Color = clBtnFace
|
||||
Font.Charset = DEFAULT_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -11
|
||||
Font.Name = 'Tahoma'
|
||||
Font.Style = []
|
||||
OldCreateOrder = True
|
||||
OnCreate = FormCreate
|
||||
OnDestroy = FormDestroy
|
||||
DesignSize = (
|
||||
788
|
||||
477)
|
||||
PixelsPerInch = 96
|
||||
TextHeight = 13
|
||||
object Thumbnail: TImage
|
||||
Left = 620
|
||||
Top = 41
|
||||
Width = 160
|
||||
Height = 151
|
||||
Anchors = [akTop, akRight]
|
||||
Center = True
|
||||
Proportional = True
|
||||
Stretch = True
|
||||
end
|
||||
object Label1: TLabel
|
||||
Left = 620
|
||||
Top = 380
|
||||
Width = 50
|
||||
Height = 13
|
||||
Anchors = [akRight, akBottom]
|
||||
Caption = 'New value'
|
||||
Color = clBtnFace
|
||||
ParentColor = False
|
||||
end
|
||||
object Label2: TLabel
|
||||
Left = 618
|
||||
Top = 330
|
||||
Width = 18
|
||||
Height = 13
|
||||
Anchors = [akRight, akBottom]
|
||||
Caption = 'Tag'
|
||||
Color = clBtnFace
|
||||
ParentColor = False
|
||||
end
|
||||
object BtnLoad: TButton
|
||||
Left = 728
|
||||
Top = 8
|
||||
Width = 52
|
||||
Height = 25
|
||||
Anchors = [akTop, akRight]
|
||||
Caption = 'Load'
|
||||
TabOrder = 0
|
||||
OnClick = BtnLoadClick
|
||||
end
|
||||
object CbFilename: TComboBox
|
||||
Left = 8
|
||||
Top = 9
|
||||
Width = 677
|
||||
Height = 21
|
||||
Anchors = [akLeft, akTop, akRight]
|
||||
TabOrder = 1
|
||||
Text = '..\test-image.jpg'
|
||||
OnSelect = CbFilenameSelect
|
||||
end
|
||||
object Memo: TMemo
|
||||
Left = 8
|
||||
Top = 41
|
||||
Width = 604
|
||||
Height = 384
|
||||
Anchors = [akLeft, akTop, akRight, akBottom]
|
||||
ScrollBars = ssBoth
|
||||
TabOrder = 2
|
||||
end
|
||||
object BtnBrowse: TButton
|
||||
Left = 689
|
||||
Top = 8
|
||||
Width = 35
|
||||
Height = 25
|
||||
Anchors = [akTop, akRight]
|
||||
Caption = '...'
|
||||
TabOrder = 3
|
||||
OnClick = BtnBrowseClick
|
||||
end
|
||||
object Panel1: TPanel
|
||||
Left = 0
|
||||
Top = 442
|
||||
Width = 788
|
||||
Height = 35
|
||||
Align = alBottom
|
||||
BevelOuter = bvNone
|
||||
TabOrder = 4
|
||||
DesignSize = (
|
||||
788
|
||||
35)
|
||||
object CbVerbosity: TComboBox
|
||||
Left = 8
|
||||
Top = 1
|
||||
Width = 192
|
||||
Height = 21
|
||||
Style = csDropDownList
|
||||
ItemIndex = 2
|
||||
TabOrder = 0
|
||||
Text = 'Hex tag IDs'
|
||||
Items.Strings = (
|
||||
'Tag names only'
|
||||
'Decimal tag IDs'
|
||||
'Hex tag IDs')
|
||||
end
|
||||
object CbDecodeValue: TCheckBox
|
||||
Left = 208
|
||||
Top = 3
|
||||
Width = 96
|
||||
Height = 19
|
||||
Caption = 'Decode values'
|
||||
Checked = True
|
||||
State = cbChecked
|
||||
TabOrder = 1
|
||||
OnClick = CbDecodeValueClick
|
||||
end
|
||||
object CbTruncateBinaryTags: TCheckBox
|
||||
Left = 312
|
||||
Top = 3
|
||||
Width = 127
|
||||
Height = 19
|
||||
Caption = 'Truncate binary tags'
|
||||
Checked = True
|
||||
State = cbChecked
|
||||
TabOrder = 2
|
||||
OnClick = CbTruncateBinaryTagsClick
|
||||
end
|
||||
object CbBinaryAsASCII: TCheckBox
|
||||
Left = 447
|
||||
Top = 3
|
||||
Width = 123
|
||||
Height = 19
|
||||
Caption = 'Binary tags as ASCII'
|
||||
TabOrder = 3
|
||||
OnClick = CbBinaryAsASCIIClick
|
||||
end
|
||||
object BtnSave: TButton
|
||||
Left = 650
|
||||
Top = 0
|
||||
Width = 130
|
||||
Height = 25
|
||||
Anchors = [akTop, akRight]
|
||||
Caption = 'Save as "_modified"'
|
||||
Enabled = False
|
||||
TabOrder = 4
|
||||
OnClick = BtnSaveClick
|
||||
end
|
||||
end
|
||||
object CbTags: TComboBox
|
||||
Left = 620
|
||||
Top = 349
|
||||
Width = 160
|
||||
Height = 21
|
||||
Style = csDropDownList
|
||||
Anchors = [akRight, akBottom]
|
||||
DropDownCount = 32
|
||||
TabOrder = 5
|
||||
OnSelect = CbTagsSelect
|
||||
end
|
||||
object EdNewTagValue: TEdit
|
||||
Left = 620
|
||||
Top = 399
|
||||
Width = 160
|
||||
Height = 21
|
||||
Anchors = [akRight, akBottom]
|
||||
TabOrder = 6
|
||||
end
|
||||
object OpenDialog: TOpenDialog
|
||||
DefaultExt = '.jpg'
|
||||
Filter =
|
||||
'All supported images (*.jpg; *.jpeg; *.jfe); *.tiff; *.tif|*.jpg' +
|
||||
';*.jpeg;*.jfe;*.tiff;*.tif|JPG files (*.jpg; *.jpeg; *.jfe)|*.jp' +
|
||||
'g;*.jpeg;*.jfe|TIFF files (*.tiff; *.tif)|*.tiff;*.tif'
|
||||
Left = 248
|
||||
Top = 168
|
||||
end
|
||||
end
|
449
components/fpexif/delphi examples/simple_demo/sdmain.pas
Normal file
449
components/fpexif/delphi examples/simple_demo/sdmain.pas
Normal file
@ -0,0 +1,449 @@
|
||||
unit sdMain;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, Types, Forms, Controls, Graphics, Dialogs, StdCtrls,
|
||||
ExtCtrls, fpeMetadata, fpeMakerNote;
|
||||
|
||||
type
|
||||
|
||||
{ TMainForm }
|
||||
|
||||
TMainForm = class(TForm)
|
||||
BtnLoad: TButton;
|
||||
BtnBrowse: TButton;
|
||||
BtnSave: TButton;
|
||||
CbDecodeValue: TCheckBox;
|
||||
CbFilename: TComboBox;
|
||||
CbVerbosity: TComboBox;
|
||||
CbTruncateBinaryTags: TCheckBox;
|
||||
CbBinaryAsASCII: TCheckBox;
|
||||
CbTags: TComboBox;
|
||||
EdNewTagValue: TEdit;
|
||||
Label1: TLabel;
|
||||
Label2: TLabel;
|
||||
Thumbnail: TImage;
|
||||
Memo: TMemo;
|
||||
OpenDialog: TOpenDialog;
|
||||
Panel1: TPanel;
|
||||
procedure BtnLoadClick(Sender: TObject);
|
||||
procedure BtnBrowseClick(Sender: TObject);
|
||||
procedure BtnSaveClick(Sender: TObject);
|
||||
procedure CbBinaryAsASCIIClick(Sender: TObject);
|
||||
procedure CbDecodeValueClick(Sender: TObject);
|
||||
procedure CbFilenameSelect(Sender: TObject);
|
||||
procedure CbTagsSelect(Sender: TObject);
|
||||
procedure CbTruncateBinaryTagsClick(Sender: TObject);
|
||||
procedure CbVerbosityChange(Sender: TObject);
|
||||
procedure EdNewTagValueEditingDone(Sender: TObject);
|
||||
procedure FormCreate(Sender: TObject);
|
||||
procedure FormDestroy(Sender: TObject);
|
||||
private
|
||||
FImgInfo: TImgInfo;
|
||||
FModified: Boolean;
|
||||
procedure AddToHistory(AFileName: String);
|
||||
procedure DisplayMetadata;
|
||||
procedure LoadFile(const AFileName: String);
|
||||
procedure LoadThumbnail;
|
||||
procedure PopulateTagCombo;
|
||||
procedure ReadFromIni;
|
||||
procedure UpdateCaption(AInit: Boolean);
|
||||
procedure WriteToIni;
|
||||
|
||||
public
|
||||
procedure BeforeRun;
|
||||
|
||||
end;
|
||||
|
||||
var
|
||||
MainForm: TMainForm;
|
||||
|
||||
implementation
|
||||
|
||||
{$R *.dfm}
|
||||
|
||||
uses
|
||||
IniFiles, jpeg, fpeGlobal, fpeTags, fpeExifData;
|
||||
|
||||
{ TMainForm }
|
||||
|
||||
procedure TMainForm.AddToHistory(AFileName: String);
|
||||
var
|
||||
i: Integer;
|
||||
begin
|
||||
if (AFileName = '') or (not FileExists(AFileName)) then
|
||||
exit;
|
||||
|
||||
i := CbFileName.Items.Indexof(AFileName);
|
||||
if i > -1 then
|
||||
CbFileName.Items.Delete(i);
|
||||
CbFileName.Items.Insert(0, AFileName);
|
||||
CbFileName.ItemIndex := 0;
|
||||
end;
|
||||
|
||||
procedure TMainForm.BeforeRun;
|
||||
begin
|
||||
ReadFromIni;
|
||||
end;
|
||||
|
||||
procedure TMainForm.BtnBrowseClick(Sender: TObject);
|
||||
var
|
||||
olddir: String;
|
||||
begin
|
||||
olddir := GetCurrentDir;
|
||||
OpenDialog.FileName := '';
|
||||
if OpenDialog.Execute then begin
|
||||
AddToHistory(OpenDialog.Filename);
|
||||
SetCurrentDir(oldDir);
|
||||
LoadFile(OpenDialog.Filename);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMainForm.BtnLoadClick(Sender: TObject);
|
||||
begin
|
||||
LoadFile(CbFilename.Text);
|
||||
end;
|
||||
|
||||
procedure TMainForm.BtnSaveClick(Sender: TObject);
|
||||
var
|
||||
fn, ext: String;
|
||||
begin
|
||||
ext := ExtractFileExt(CbFilename.Text);
|
||||
fn := ChangeFileExt(CbFileName.Text, '');
|
||||
if pos('_modified', fn) <> Length(fn) - Length('modified') then
|
||||
fn := fn + '_modified' + ext
|
||||
else
|
||||
fn := CbFilename.Text;
|
||||
FImgInfo.SaveToFile(fn);
|
||||
MessageDlg(Format('File saved as "%s"', [fn]), mtInformation, [mbOK], 0);
|
||||
end;
|
||||
|
||||
procedure TMainForm.CbBinaryAsASCIIClick(Sender: TObject);
|
||||
begin
|
||||
DisplayMetadata;
|
||||
end;
|
||||
|
||||
procedure TMainForm.CbDecodeValueClick(Sender: TObject);
|
||||
begin
|
||||
DisplayMetaData;
|
||||
end;
|
||||
|
||||
procedure TMainForm.CbFilenameSelect(Sender: TObject);
|
||||
begin
|
||||
LoadFile(CbFileName.Text);
|
||||
end;
|
||||
|
||||
procedure TMainForm.CbTagsSelect(Sender: TObject);
|
||||
var
|
||||
lTag: TTag;
|
||||
decoded: Boolean;
|
||||
begin
|
||||
if FImgInfo.HasExif then begin
|
||||
lTag := FImgInfo.ExifData.TagByName[CbTags.Text];
|
||||
decoded := lTag.DecodeValue;
|
||||
lTag.DecodeValue := false;
|
||||
EdNewTagValue.Text := lTag.AsString;
|
||||
lTag.DecodeValue := decoded;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMainForm.CbTruncateBinaryTagsClick(Sender: TObject);
|
||||
begin
|
||||
DisplayMetadata;
|
||||
end;
|
||||
|
||||
procedure TMainForm.CbVerbosityChange(Sender: TObject);
|
||||
begin
|
||||
DisplayMetadata;
|
||||
end;
|
||||
|
||||
procedure TMainForm.DisplayMetadata;
|
||||
const
|
||||
SEPARATOR = ': ';
|
||||
var
|
||||
exportOptions: TExportOptions;
|
||||
begin
|
||||
Memo.Lines.Clear;
|
||||
|
||||
if FImgInfo <> nil then begin
|
||||
exportOptions := [eoShowTagName];
|
||||
case CbVerbosity.ItemIndex of
|
||||
1: Include(exportOptions, eoShowDecimalTagID);
|
||||
2: Include(exportOptions, eoShowHexTagID);
|
||||
end;
|
||||
if CbDecodeValue.Checked then
|
||||
Include(exportOptions, eoDecodeValue) else
|
||||
Exclude(exportOptions, eoDecodeValue);
|
||||
if CbTruncateBinaryTags.Checked then
|
||||
Include(exportOptions, eoTruncateBinary) else
|
||||
Exclude(exportOptions, eoTruncateBinary);
|
||||
if CbBinaryAsASCII.Checked then
|
||||
Include(exportOptions, eoBinaryAsASCII) else
|
||||
Exclude(exportOptions, eoBinaryAsASCII);
|
||||
|
||||
Memo.Lines.BeginUpdate;
|
||||
try
|
||||
if FImgInfo.ExifData <> nil then begin
|
||||
FImgInfo.ExifData.ExportOptions := exportOptions;
|
||||
FImgInfo.ExifData.ExportToStrings(Memo.Lines, SEPARATOR);
|
||||
end;
|
||||
if FImgInfo.IptcData <> nil then
|
||||
FImgInfo.IptcData.ExportToStrings(Memo.Lines, exportOptions, SEPARATOR);
|
||||
finally
|
||||
Memo.Lines.EndUpdate;
|
||||
Memo.Invalidate;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMainForm.EdNewTagValueEditingDone(Sender: TObject);
|
||||
var
|
||||
lTag: TTag;
|
||||
i: Integer;
|
||||
f: Double;
|
||||
dt: TDateTime;
|
||||
begin
|
||||
if FImgInfo.HasExif then begin
|
||||
lTag := FImgInfo.ExifData.TagByName[CbTags.Text];
|
||||
if lTag = nil then begin
|
||||
MessageDlg('Tag not found.', mtError, [mbOK], 0);
|
||||
exit;
|
||||
end;
|
||||
if lTag.ReadOnly then begin
|
||||
MessageDlg('This tag is readonly.', mtError, [mbOK], 0);
|
||||
exit;
|
||||
end;
|
||||
|
||||
if (lTag is TDateTimeTag) then begin
|
||||
if TryStrToDateTime(EdNewTagValue.Text, dt) then begin
|
||||
FModified := FModified or (TDateTimeTag(lTag).AsDateTime <> dt);
|
||||
TDateTimeTag(lTag).AsDateTime := dt;
|
||||
end else begin
|
||||
MessageDlg('Date/time value expected for this kind of tag.', mtError, [mbOK], 0);
|
||||
exit;
|
||||
end;
|
||||
end else
|
||||
if (lTag is TShutterSpeedTag) then begin
|
||||
FModified := true;
|
||||
TShutterSpeedTag(lTag).AsString := EdNewTagValue.Text;
|
||||
end else
|
||||
if (lTag is TStringTag) then begin
|
||||
FModified := FModified or (EdNewTagValue.Text <> TStringTAg(lTag).AsString);
|
||||
TStringTag(lTag).AsString := EdNewTagValue.Text;
|
||||
end else
|
||||
if (lTag is TIntegerTag) and (lTag.Count = 1) then begin
|
||||
if TryStrToInt(EdNewTagValue.Text, i) then begin
|
||||
FModified := FModified or (TIntegerTag(lTag).AsInteger <> i);
|
||||
TIntegerTag(lTag).AsInteger := i;
|
||||
end else begin
|
||||
MessageDlg('Integer value expected for this kind of tag.', mtError, [mbOK], 0);
|
||||
exit;
|
||||
end;
|
||||
end else
|
||||
if (lTag is TFloatTag) and (lTag.Count = 1) then begin
|
||||
if TryStrToFloat(EdNewTagValue.Text, f) then begin
|
||||
FModified := FModified or (TFloatTag(lTag).AsFloat <> f);
|
||||
TFloatTag(lTag).AsFloat := f;
|
||||
end else begin
|
||||
MessageDlg('Floating point value expected for this kind of tag.', mtError, [mbOK], 0);
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
DisplayMetadata;
|
||||
UpdateCaption(false);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMainForm.FormCreate(Sender: TObject);
|
||||
begin
|
||||
UpdateCaption(true);
|
||||
end;
|
||||
|
||||
procedure TMainForm.FormDestroy(Sender: TObject);
|
||||
begin
|
||||
WriteToIni;
|
||||
FImgInfo.Free;
|
||||
end;
|
||||
|
||||
procedure TMainForm.LoadFile(const AFileName: String);
|
||||
var
|
||||
exportOptions: TExportOptions;
|
||||
begin
|
||||
if FImgInfo = nil then
|
||||
FImgInfo := TImgInfo.Create;
|
||||
|
||||
try
|
||||
FImgInfo.LoadFromFile(ExpandFileName(CbFilename.Text));
|
||||
if FImgInfo.ExifData <> nil then begin
|
||||
DisplayMetadata;
|
||||
LoadThumbnail;
|
||||
PopulateTagCombo;
|
||||
AddToHistory(AFilename);
|
||||
end else begin
|
||||
Thumbnail.Picture.Assign(nil);
|
||||
CbTags.Items.Clear;
|
||||
end;
|
||||
if FImgInfo.HasWarnings then begin
|
||||
Memo.Lines.Add('');
|
||||
Memo.Lines.Add('*** WARNINGS ****');
|
||||
Memo.Lines.Add(FImgInfo.Warnings);
|
||||
end;
|
||||
UpdateCaption(false);
|
||||
FModified := false;
|
||||
BtnSave.Enabled := FImgInfo.ImgFormat = ifJpeg;
|
||||
except
|
||||
on E:EFpExifReader do begin
|
||||
Memo.Lines.Text := E.Message;
|
||||
Thumbnail.Picture.Assign(nil);
|
||||
CbTags.Items.Clear;
|
||||
ShowMessage(E.Message);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMainForm.LoadThumbnail;
|
||||
var
|
||||
ms: TMemoryStream;
|
||||
jpg: TJpegImage;
|
||||
begin
|
||||
if not FImgInfo.HasThumbnail then
|
||||
exit;
|
||||
|
||||
//if (FImgInfo.ExifData = nil) or (not FImgInfo.Exifdata.HasThumbnail) then
|
||||
// exit;
|
||||
|
||||
ms := TMemoryStream.Create;
|
||||
try
|
||||
FImgInfo.SaveThumbnailToStream(ms);
|
||||
ms.Position := 0;
|
||||
jpg := TJpegImage.Create;
|
||||
try
|
||||
jpg.LoadFromStream(ms);
|
||||
Thumbnail.Picture.Assign(jpg);
|
||||
finally
|
||||
jpg.Free;
|
||||
end;
|
||||
finally
|
||||
ms.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMainForm.PopulateTagCombo;
|
||||
var
|
||||
i: Integer;
|
||||
L: TStrings;
|
||||
lTag: TTag;
|
||||
begin
|
||||
L := TStringList.Create;
|
||||
try
|
||||
if FImgInfo.HasExif then
|
||||
for i:=0 to FImgInfo.ExifData.TagCount-1 do begin
|
||||
lTag := FImgInfo.ExifData.TagByIndex[i];
|
||||
if not lTag.ReadOnly or lTag.IsVolatile then
|
||||
L.Add(GroupNames[lTag.Group] + '.' + lTag.Name);
|
||||
end;
|
||||
CbTags.Items.Assign(L);
|
||||
CbTags.ItemIndex := -1;
|
||||
finally
|
||||
L.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
function CreateIni: TCustomIniFile;
|
||||
begin
|
||||
Result := TMemIniFile.Create(ChangeFileExt(Application.ExeName, '.ini'));
|
||||
end;
|
||||
|
||||
procedure TMainForm.ReadFromIni;
|
||||
var
|
||||
ini: TCustomIniFile;
|
||||
list: TStrings;
|
||||
i: Integer;
|
||||
W, H, L, T: Integer;
|
||||
R: TRect;
|
||||
begin
|
||||
ini := CreateIni;
|
||||
try
|
||||
list := TStringList.Create;
|
||||
try
|
||||
if WindowState = wsNormal then begin
|
||||
W := ini.ReadInteger('MainForm', 'Width', Width);
|
||||
H := ini.ReadInteger('MainForm', 'Height', Height);
|
||||
L := ini.ReadInteger('MainForm', 'Left', Left);
|
||||
T := ini.ReadInteger('MainForm', 'Top', Top);
|
||||
R := Screen.DesktopRect;
|
||||
if W > R.Right - R.Left then W := R.Right - R.Left;
|
||||
if L+W > R.Right then L := R.Right - W;
|
||||
if L < R.Left then L := R.Left;
|
||||
if H > R.Bottom - R.Top then H := R.Bottom - R.Top;
|
||||
if T+H > R.Bottom then T := R.Bottom - H;
|
||||
if T < R.Top then T := R.Top;
|
||||
SetBounds(L, T, W, H);
|
||||
end;
|
||||
|
||||
CbVerbosity.ItemIndex := ini.ReadInteger('Settings', 'Verbosity', CbVerbosity.ItemIndex);
|
||||
CbDecodeValue.Checked := ini.ReadBool('Settings', 'DecodeValue', CbDecodeValue.Checked);
|
||||
|
||||
ini.ReadSection('History', list);
|
||||
for i:=list.Count-1 downto 0 do // count downward because AddToHistory adds to the beginning of the list
|
||||
AddToHistory(ini.ReadString('History', list[i], ''));
|
||||
if CbFilename.Items.Count = 0 then
|
||||
AddToHistory('..\test-image.jpg');
|
||||
|
||||
|
||||
CbFilename.ItemIndex := 0;
|
||||
finally
|
||||
list.Free;
|
||||
end;
|
||||
finally
|
||||
ini.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMainForm.UpdateCaption(AInit: Boolean);
|
||||
const
|
||||
DEFAULT_CAPTION = 'Picture metadata viewer';
|
||||
var
|
||||
mask: String;
|
||||
begin
|
||||
if AInit then
|
||||
Caption := DEFAULT_CAPTION
|
||||
else
|
||||
begin
|
||||
if FModified then
|
||||
mask := '%s - [*] %s' else
|
||||
mask := '%s - %s';
|
||||
if FImgInfo.Filename <> '' then
|
||||
Caption := Format(mask, [DEFAULT_CAPTION, '"' + FImgInfo.FileName + '"'])
|
||||
else
|
||||
Caption := Format(mask, [DEFAULT_CAPTION, 'ERROR']);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMainForm.WriteToIni;
|
||||
var
|
||||
ini: TCustomIniFile;
|
||||
i: Integer;
|
||||
begin
|
||||
ini := CreateIni;
|
||||
try
|
||||
ini.WriteInteger('MainForm', 'Left', Left);
|
||||
ini.WriteInteger('MainForm', 'Top', Top);
|
||||
ini.WriteInteger('MainForm', 'Width', Width);
|
||||
ini.WriteInteger('MainForm', 'Height', Height);
|
||||
|
||||
ini.WriteInteger('Settings', 'Verbosity', CbVerbosity.ItemIndex);
|
||||
ini.WriteBool('Settings', 'DecodeValue', CbDecodeValue.Checked);
|
||||
|
||||
for i:=0 to CbFileName.Items.Count-1 do
|
||||
if (CbFilename.Items[i] <> '') and FileExists(CbFilename.Items[i]) then
|
||||
ini.WriteString('History', 'Item'+IntToStr(i+1), CbFilename.Items[i]);
|
||||
ini.UpdateFile;
|
||||
finally
|
||||
ini.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
end.
|
Reference in New Issue
Block a user