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:
wp_xxyyzz
2020-02-17 23:17:39 +00:00
parent 9779c4beba
commit acb60ffd33
14 changed files with 2688 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
program MetadataViewer;
uses
Forms,
mdvMain in 'mdvMain.pas' {Form1};
{$R *.res}
begin
Application.Initialize;
Application.CreateForm(TMainForm, MainForm);
MainForm.BeforeRun;
Application.Run;
end.

View File

@@ -0,0 +1,144 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectGuid>{2958AB0F-1A2B-4CDE-B1F2-B6C5B3644858}</ProjectGuid>
<MainSource>MetadataViewer.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>MetadataViewer</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>
<Icon_MainIcon>MetadataViewer_Icon.ico</Icon_MainIcon>
<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)'!=''">
<Manifest_File>$(BDS)\bin\default_app.manifest</Manifest_File>
<Icon_MainIcon>MetadataViewer_Icon.ico</Icon_MainIcon>
<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="'$(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>
<DCC_DebugDCUs>true</DCC_DebugDCUs>
</PropertyGroup>
<ItemGroup>
<DelphiCompile Include="$(MainSource)">
<MainSource>MainSource</MainSource>
</DelphiCompile>
<DCCReference Include="mdvMain.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">MetadataViewer.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>

View File

@@ -0,0 +1,319 @@
object MainForm: TMainForm
Left = 430
Top = 141
Caption = 'Metadata viewer'
ClientHeight = 714
ClientWidth = 926
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = True
ShowHint = True
OnCreate = FormCreate
OnDestroy = FormDestroy
PixelsPerInch = 96
TextHeight = 13
object Splitter2: TSplitter
Left = 274
Top = 0
Width = 5
Height = 691
end
object ShellPanel: TPanel
Left = 0
Top = 0
Width = 274
Height = 691
Align = alLeft
BevelOuter = bvNone
TabOrder = 0
object Splitter1: TSplitter
Left = 0
Top = 269
Width = 274
Height = 5
Cursor = crVSplit
Align = alTop
end
object PreviewImage: TImage
Left = 0
Top = 547
Width = 274
Height = 144
Hint = 'Thumbnail image embedded in the image file'
Align = alBottom
Center = True
Proportional = True
Stretch = True
end
object ShellTreeView: TDirectoryOutline
Left = 0
Top = 0
Width = 274
Height = 269
Hint = 'Navigate to the folder with your images.'
Align = alTop
ItemHeight = 13
Options = [ooDrawFocusRect]
PictureLeaf.Data = {
46030000424D460300000000000036000000280000000E0000000E0000000100
2000000000001003000000000000000000000000000000000000800080008000
8000800080008000800080008000800080008000800080008000800080008000
8000800080008000800080008000800080008000800080008000800080008000
8000800080008000800080008000800080008000800080008000800080008000
8000800080008000800080008000800080008000800080008000800080008000
8000800080008000800080008000800080008000800080008000800080008000
8000800080000000000000000000000000000000000000000000000000000000
00000000000000000000000000008000800080008000800080000000000000FF
FF00FFFFFF0000FFFF00FFFFFF0000FFFF00FFFFFF0000FFFF00FFFFFF0000FF
FF000000000080008000800080008000800000000000FFFFFF0000FFFF00FFFF
FF0000FFFF00FFFFFF0000FFFF00FFFFFF0000FFFF00FFFFFF00000000008000
800080008000800080000000000000FFFF00FFFFFF0000FFFF00FFFFFF0000FF
FF00FFFFFF0000FFFF00FFFFFF0000FFFF000000000080008000800080008000
800000000000FFFFFF0000FFFF00FFFFFF0000FFFF00FFFFFF0000FFFF00FFFF
FF0000FFFF00FFFFFF00000000008000800080008000800080000000000000FF
FF00FFFFFF0000FFFF00FFFFFF0000FFFF00FFFFFF0000FFFF00FFFFFF0000FF
FF000000000080008000800080008000800000000000FFFFFF0000FFFF00FFFF
FF0000FFFF00FFFFFF0000FFFF00FFFFFF0000FFFF00FFFFFF00000000008000
8000800080008000800000000000000000000000000000000000000000000000
0000000000000000000000000000000000008000800080008000800080008000
80008000800000000000FFFFFF0000FFFF00FFFFFF0000FFFF00000000008000
8000800080008000800080008000800080008000800080008000800080008080
8000000000000000000000000000000000008080800080008000800080008000
8000800080008000800080008000800080008000800080008000800080008000
8000800080008000800080008000800080008000800080008000800080008000
80008000800080008000}
TabOrder = 0
OnChange = ShellTreeViewChange
Data = {10}
end
object ShellListView: TFileListBox
Left = 0
Top = 274
Width = 274
Height = 260
Hint = 'Select the image for which you want to see the metadata'
Align = alClient
Mask = '*.jpg;*.jpeg;*.jpe;*.tiff;*.tif'
ShowGlyphs = True
TabOrder = 2
OnChange = ShellListViewChange
end
object Panel4: TPanel
Left = 0
Top = 534
Width = 274
Height = 13
Align = alBottom
AutoSize = True
BevelOuter = bvNone
TabOrder = 1
object Label1: TLabel
Left = 8
Top = 0
Width = 79
Height = 13
Caption = 'Thumbnail image'
Color = clBtnFace
ParentColor = False
end
end
end
object Panel2: TPanel
Left = 279
Top = 0
Width = 647
Height = 691
Align = alClient
BevelOuter = bvNone
TabOrder = 2
object Splitter3: TSplitter
Left = 0
Top = 571
Width = 647
Height = 5
Cursor = crVSplit
Align = alBottom
ExplicitTop = 562
end
object Panel3: TPanel
Left = 0
Top = 0
Width = 647
Height = 21
Align = alTop
AutoSize = True
BevelOuter = bvNone
BorderWidth = 4
TabOrder = 0
object FilenameInfo: TLabel
Left = 4
Top = 4
Width = 23
Height = 13
Caption = 'File: '
Color = clBtnFace
ParentColor = False
end
end
object PageControl1: TPageControl
Left = 0
Top = 21
Width = 647
Height = 550
ActivePage = PgMetadata
Align = alClient
TabOrder = 1
OnChange = PageControl1Change
object PgMetadata: TTabSheet
Caption = 'Meta data'
ExplicitLeft = 0
ExplicitTop = 0
ExplicitWidth = 0
ExplicitHeight = 0
object TagListView: TListView
Left = 0
Top = 0
Width = 639
Height = 503
Align = alClient
Columns = <
item
Caption = 'Group'
Width = 120
end
item
Caption = 'Tag ID'
Width = 60
end
item
Caption = 'Property'
Width = 220
end
item
AutoSize = True
Caption = 'Value'
end>
HideSelection = False
ReadOnly = True
RowSelect = True
SortType = stText
TabOrder = 0
ViewStyle = vsReport
OnCompare = TagListViewCompare
OnSelectItem = TagListViewSelectItem
end
object Panel1: TPanel
Left = 0
Top = 503
Width = 639
Height = 19
Align = alBottom
AutoSize = True
BevelOuter = bvNone
TabOrder = 1
ExplicitTop = 501
object CbDecodeMakerNotes: TCheckBox
Left = 0
Top = 0
Width = 127
Height = 19
Hint = 'Try to decode information in the MakerNote tag if possible'
Caption = 'Decode MakerNotes'
Checked = True
State = cbChecked
TabOrder = 0
end
end
end
object PgImage: TTabSheet
Caption = 'Image'
ExplicitLeft = 0
ExplicitTop = 0
ExplicitWidth = 0
ExplicitHeight = 0
object Image: TImage
Left = 0
Top = 0
Width = 639
Height = 522
Align = alClient
Center = True
Proportional = True
Stretch = True
ExplicitHeight = 545
end
end
end
object Messages: TMemo
Left = 0
Top = 576
Width = 647
Height = 90
Align = alBottom
TabOrder = 2
end
object DateTimePanel: TPanel
Left = 0
Top = 666
Width = 647
Height = 25
Align = alBottom
AutoSize = True
BevelOuter = bvNone
TabOrder = 3
object LblChangeDate: TLabel
Left = 4
Top = 5
Width = 124
Height = 13
Caption = 'Change EXIF date/time to'
Color = clBtnFace
ParentColor = False
end
object EdChangeDate: TEdit
Left = 144
Top = 1
Width = 152
Height = 21
Hint = 'New date to be assigned to the selected image'
TabOrder = 0
end
object BtnChangeDate: TButton
Left = 304
Top = 0
Width = 67
Height = 25
Hint = 'Replaces the image date.'
Caption = 'Execute'
TabOrder = 1
OnClick = BtnChangeDateClick
end
end
end
object StatusBar1: TStatusBar
Left = 0
Top = 691
Width = 926
Height = 23
Panels = <
item
Width = 150
end
item
Width = 150
end
item
Width = 250
end
item
Width = 150
end
item
Width = 100
end>
end
end

View File

@@ -0,0 +1,605 @@
unit mdvMain;
{$IFDEF FPC}
!!! THIS PROGRAM IS INTENDED FOR DELPHI ONLY
{$ENDIF}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs,
ExtCtrls, ComCtrls, StdCtrls, DirOutLn, FileCtrl, jpeg,
fpeGlobal, fpeMetadata, fpeMakerNote,
Grids, Outline;
type
{ TMainForm }
TMainForm = class(TForm)
BtnChangeDate: TButton;
CbDecodeMakerNotes: TCheckBox;
EdChangeDate: TEdit;
FilenameInfo: TLabel;
Image: TImage;
Label1: TLabel;
LblChangeDate: TLabel;
Messages: TMemo;
PageControl1: TPageControl;
Panel1: TPanel;
Panel2: TPanel;
Panel3: TPanel;
DateTimePanel: TPanel;
Panel4: TPanel;
PreviewImage: TImage;
Splitter3: TSplitter;
StatusBar1: TStatusBar;
PgMetadata: TTabSheet;
PgImage: TTabSheet;
TagListView: TListView;
ShellPanel: TPanel;
ShellTreeView: TDirectoryOutline;
ShellListView: TFileListbox;
Splitter1: TSplitter;
Splitter2: TSplitter;
procedure BtnChangeDateClick(Sender: TObject);
procedure CbShowTagIDsChange(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure PageControl1Change(Sender: TObject);
(*
procedure ShellListViewSelectItem(Sender: TObject; Item: TListItem;
Selected: Boolean);
procedure ShellTreeViewGetImageIndex(Sender: TObject; Node: TTreeNode);
procedure ShellTreeViewSelectionChanged(Sender: TObject);
*)
procedure TagListViewCompare(Sender: TObject; Item1, Item2: TListItem;
Data: Integer; var Compare: Integer);
procedure TagListViewSelectItem(Sender: TObject; Item: TListItem;
Selected: Boolean);
procedure ShellTreeViewChange(Sender: TObject);
procedure ShellListViewChange(Sender: TObject);
private
FFileName: String;
FImgInfo: TImgInfo;
FImageLoaded: Boolean;
FImageOrientation: TExifOrientation;
procedure LoadFile(const AFileName: String);
procedure LoadFromIni;
procedure SaveToIni;
procedure UpdateCaption;
public
procedure BeforeRun;
end;
var
MainForm: TMainForm;
implementation
{$R *.dfm}
uses
Types, IniFiles, Math, StrUtils, DateUtils,
fpeTags, fpeExifData, fpeIptcData;
const
TAG_ID_CAPTION = 'Tag ID';
LineEnding = #13#10;
function CalcIniName: String;
begin
Result := ChangeFileExt(Application.ExeName, '.ini');
end;
procedure RotateBitmap(const ABitmap: TBitmap; AOrientation: TExifOrientation);
{
Var
bmp: TBitmap;
srcImg, dstImg: TLazIntfImage;
imgHandle, imgMaskHandle: HBitmap;
i, j: integer;
w1, h1: Integer; // Input bitmap width and height diminished by 1
}
Begin
exit;
(*
Assert(ABitmap <> nil, 'RotateBitmap: Input bitmap is expected not to be nil.');
if (AOrientation = eoUnknown) or (AOrientation = eoNormal) then
exit;
w1 := ABitmap.Width - 1;
h1 := ABitmap.Height - 1;
srcImg := TLazIntfImage.Create(0, 0);
try
srcImg.LoadFromBitmap(ABitmap.Handle, ABitmap.MaskHandle);
bmp := TBitmap.Create;
try
dstImg := TLazIntfImage.Create(0, 0);
try
if AOrientation in [eoRotate90, eoRotate270, eoMirrorHorRot90, eoMirrorHorRot270] then
begin
bmp.SetSize(ABitmap.Height, ABitmap.Width);
dstImg.LoadFromBitmap(bmp.Handle, bmp.MaskHandle);
case AOrientation of
eoRotate90:
for i:=0 to w1 do
for j:=0 to h1 do
dstImg.Colors[h1-j, i] := srcImg.Colors[i, j];
eoRotate270:
for i:=0 to w1 do
for j:=0 to h1 do
dstImg.Colors[j, w1-i] := srcImg.Colors[i, j];
eoMirrorHorRot90:
for i:=0 to w1 do
for j:=0 to h1 do
dstImg.Colors[h1-j, w1-i] := srcImg.Colors[i, j];
eoMirrorHorRot270:
for i:=0 to w1 do
for j:=0 to h1 do
dstImg.Colors[j, i] := srcImg.Colors[i, j];
end;
end else
if AOrientation in [eoRotate180, eoMirrorHor, eoMirrorVert] then
begin
bmp.SetSize(ABitmap.Width, ABitmap.Height);
dstImg.LoadFromBitmap(bmp.Handle, bmp.MaskHandle);
case AOrientation of
eoRotate180:
for i:=0 to w1 do
for j:=0 to h1 do
dstImg.Colors[w1-i, h1-j] := srcImg.Colors[i, j];
eoMirrorHor:
for j:=0 to h1 do
for i:=0 to w1 do
dstImg.Colors[w1-i, j] := srcImg.Colors[i, j];
eoMirrorVert:
for i:=0 to w1 do
for j:=0 to h1 do
dstImg.Colors[i, h1-j] := srcImg.Colors[i, j];
end;
end;
dstImg.CreateBitmaps(imgHandle, imgMaskHandle, false);
bmp.Handle := ImgHandle;
bmp.MaskHandle := ImgMaskHandle;
finally
dstImg.Free;
end;
ABitmap.Assign(bmp);
finally
bmp.Free;
end;
finally
srcImg.Free;
end;
*)
end;
{ TMainForm }
procedure TMainForm.BeforeRun;
begin
LoadFromIni;
end;
procedure TMainForm.FormCreate(Sender: TObject);
begin
//ShellListView.Parent.DoubleBuffered := true;
end;
procedure TMainForm.BtnChangeDateClick(Sender: TObject);
var
lTag: TTag;
dt: TDateTime;
fn: String;
begin
if (FImgInfo = nil) or (FImgInfo.ExifData = nil) then
exit;
if not TryStrToDateTime(EdChangeDate.Text, dt) then begin
MessageDlg('No valid date/time. Use your locale settings.', mtError, [mbOK], 0);
exit;
end;
lTag := FImgInfo.ExifData.TagByName['DateTimeOriginal'];
if lTag <> nil then
TDateTimeTag(lTag).AsDateTime := dt;
lTag := FImgInfo.ExifData.TagByName['DateTimeDigitized'];
if lTag <> nil then
TDateTimeTag(lTag).AsDateTime := dt;
lTag := FImgInfo.ExifData.TagByName['DateTime'];
if lTag <> nil then
TDateTimeTag(lTag).AsDateTime := dt;
fn := FImgInfo.FileName;
fn := ChangeFileExt(fn, '') + '_modified' + ExtractFileExt(fn);
FImgInfo.SaveToFile(fn);
end;
procedure TMainForm.CbShowTagIDsChange(Sender: TObject);
var
c: TListColumn;
i: Integer;
begin
TagListView.Items.BeginUpdate;
try
c := nil;
for i:=0 to TagListView.Columns.Count-1 do
if TagListView.Columns[i].Caption = TAG_ID_CAPTION then begin
c := TagListView.Columns[i];
break;
end;
{
if c <> nil then
c.Visible := CbShowTagIDs.Checked;;
}
finally
TagListView.Items.EndUpdate;
end;
end;
procedure TMainForm.FormDestroy(Sender: TObject);
begin
try
SaveToIni;
except
end;
FImgInfo.Free;
end;
type
TMyPicture = class(TPicture);
procedure TMainForm.LoadFile(const AFileName: String);
var
lTag: TTag;
item: TListItem;
i: Integer;
ms: TMemoryStream;
suffix: String;
crs: TCursor;
jpg: TJpegImage;
begin
FImageLoaded := false;
FFileName := AFileName;
Image.Picture.Assign(nil);
PreviewImage.Picture.Assign(nil);
TagListView.Items.BeginUpdate;
try
TagListView.Clear;
FImgInfo.Free;
FImgInfo := TImgInfo.Create;
try
try
if CbDecodeMakerNotes.Checked then
FImgInfo.MetadataKinds := FImgInfo.MetadataKinds + [mdkExif] - [mdkExifNoMakerNotes]
else
FImgInfo.MetadataKinds := FImgInfo.MetadataKinds - [mdkExif] + [mdkExifNoMakerNotes];
FImgInfo.LoadFromFile(AFileName);
Messages.Hide;
except
on E:EFpExif do begin
Messages.Lines.Text := E.Message;
Messages.Show;
end;
end;
if FImgInfo.HasExif then begin
FImageOrientation := FImgInfo.ExifData.ImgOrientation;
FImgInfo.ExifData.ExportOptions := FImgInfo.ExifData.ExportOptions + [eoTruncateBinary];
for i := 0 to FImgInfo.ExifData.TagCount-1 do begin
lTag := FImgInfo.ExifData.TagByIndex[i];
if lTag is TMakerNoteStringTag then
suffix := ':' + IntToStr(TMakerNoteStringTag(lTag).Index)
else if lTag is TMakerNoteIntegerTag then
suffix := ':' + IntToStr(TMakerNoteIntegerTag(lTag).Index)
else if lTag is TMakerNoteFloatTag then
suffix := ':' + IntToStr(TMakerNoteFloatTag(lTag).Index)
else
suffix := '';
if lTag is TVersionTag then
TVersionTag(lTag).Separator := '.';
item := TagListView.Items.Add;
item.Data := lTag;
item.Caption := 'EXIF.' + NiceGroupNames[lTag.Group];
item.SubItems.Add(Format('$%.04x:$%.04x%s', [lTag.TagIDRec.Parent, lTag.TagIDRec.Tag, suffix]));
item.SubItems.Add(lTag.Description);
item.SubItems.Add(lTag.AsString);
end;
lTag := FImgInfo.ExifData.TagByName['DateTimeOriginal'];
if lTag <> nil then
EdChangeDate.Text := DateTimeToStr(TDateTimeTag(lTag).AsDateTime)
else
EdChangeDate.Text := '';
DateTimePanel.Show;
end else
DateTimePanel.Hide;
if FImgInfo.HasIptc then begin
for i := 0 to FImgInfo.IptcData.TagCount-1 do begin
lTag := FImgInfo.IptcData.TagByIndex[i];
item := TagListView.Items.Add;
item.Data := lTag;
item.Caption := 'IPTC';
item.SubItems.Add(lTag.Description);
item.SubItems.Add(lTag.AsString);
end;
end;
if FImgInfo.HasThumbnail then begin
ms := TMemoryStream.Create;
try
try
FImgInfo.SaveThumbnailToStream(ms);
ms.Position := 0;
jpg := TJpegImage.Create;
try
jpg.LoadFromStream(ms);
PreviewImage.Picture.Assign(jpg);
finally
jpg.Free;
end;
// TMyPicture(PreviewImage.Picture).LoadFromStream(ms); // cast needed for old Delphi
//RotateBitmap(PreviewImage.Picture.Bitmap, FImageOrientation);
except
on E:Exception do Messages.Lines.Add(E.Message);
end;
finally
ms.Free;
end;
end else
;
//PreviewImage.Picture.Clear;
if FImgInfo.HasWarnings then begin
Messages.Lines.Text := FImgInfo.Warnings;
Messages.Show;
end;
except
on E:Exception do begin
FreeAndNil(FImgInfo);
Messages.Lines.Text := E.Message;
Messages.Show;
end;
end;
if PageControl1.ActivePage = PgImage then begin
crs := Screen.Cursor;
try
Screen.Cursor := crHourglass;
Image.Picture.LoadFromFile(AFileName);
{
if Assigned(FImgInfo) and Assigned(FImgInfo.ExifData) then
RotateBitmap(Image.Picture.Bitmap, FImageOrientation);
}
FImageLoaded := true;
finally
Screen.Cursor := crs;
end;
end;
UpdateCaption;
finally
TagListView.Items.EndUpdate;
//TagListView.Sort;
end;
end;
procedure TMainForm.LoadFromIni;
var
ini: TCustomIniFile;
i, W, H, L, T: Integer;
rct: TRect;
s: String;
b: Boolean;
begin
ini := TIniFile.Create(CalcIniName);
try
L := ini.ReadInteger('MainForm', 'Left', Left);
T := ini.ReadInteger('MainForm', 'Top', Top);
W := ini.ReadInteger('MainForm', 'Width', Width);
H := ini.ReadInteger('MainForm', 'Height', Height);
rct := Screen.DesktopRect;
if W > rct.Right - rct.Left then W := rct.Right - rct.Left;
if H > rct.Bottom - rct.Top then H := rct.Bottom - rct.Top;
if L < rct.Left then L := rct.Left;
if T < rct.Top then T := rct.Top;
if L+W > rct.Right then L := rct.Right - W;
if T+H > rct.Bottom then T := rct.Bottom - H;
SetBounds(L, T, W, H);
s := ini.ReadString('MainForm', 'Path', '');
if s <> '' then begin
ShellTreeView.Directory := s;
ShellListView.Directory := s;
end;
w := ini.ReadInteger('MainForm', 'LeftPanelWidth', 0);
if w <> 0 then ShellPanel.Width := w;
h := ini.ReadInteger('MainForm', 'TreeHeight', 0);
if h <> 0 then ShellTreeView.Height := h;
for i:=0 to TagListView.Columns.Count-1 do begin
w := ini.ReadInteger('TagList', 'ColWidth'+IntToStr(i), 0);
if w <> 0 then
TagListView.Columns[i].Width := w;
end;
finally
ini.Free;
end;
end;
procedure TMainForm.PageControl1Change(Sender: TObject);
var
crs: TCursor;
begin
if not FImageLoaded then begin
crs := Screen.Cursor;
try
Screen.Cursor := crHourglass;
Image.Picture.LoadFromFile(FFileName);
FImageLoaded := true;
finally
Screen.Cursor := crs;
end;
end;
end;
procedure TMainForm.SaveToIni;
var
ini: TCustomIniFile;
i: Integer;
begin
ini := TIniFile.Create(CalcIniName);
try
if WindowState = wsNormal then begin
ini.WriteInteger('MainForm', 'Left', Left);
ini.WriteInteger('MainForm', 'Top', Top);
ini.WriteInteger('MainForm', 'Width', Width);
ini.WriteInteger('MainForm', 'Height', Height);
end;
ini.WriteString('MainForm', 'Path', ShellTreeView.Directory);
ini.WriteInteger('MainForm', 'LeftPanelWidth', ShellPanel.Width);
ini.WriteInteger('MainForm', 'TreeHeight', ShellTreeView.Height);
for i:=0 to TagListView.Columns.Count-1 do
ini.WriteInteger('TagList', 'ColWidth'+IntToStr(i), TagListView.Columns[i].Width);
finally
ini.Free;
end;
end;
procedure TMainForm.ShellListViewChange(Sender: TObject);
var
fn: String;
begin
fn := ShellListView.FileName;
if fn <> '' then begin
ShellTreeView.Directory := ExtractFilePath(fn);
LoadFile(fn);
end;
end;
procedure TMainForm.ShellTreeViewChange(Sender: TObject);
begin
ShellListview.Directory := ShellTreeView.Directory;
end;
(*
procedure TMainForm.ShellListViewSelectItem(Sender: TObject; Item: TListItem;
Selected: Boolean);
var
dir, fn: String;
begin
if Selected then
begin
dir := ShellTreeView.GetPathFromNode(ShellTreeView.Selected);
fn := Item.Caption;
LoadFile(dir + fn);
end;
end;
procedure TMainForm.ShellTreeViewGetImageIndex(Sender: TObject; Node: TTreeNode);
begin
if Node = nil then
exit;
if Node.Level = 0 then
Node.ImageIndex := 0
else
if Node.Expanded then
Node.ImageIndex := 2
else
Node.ImageIndex := 1;
Node.SelectedIndex := Node.ImageIndex;
end;
procedure TMainForm.ShellTreeViewSelectionChanged(Sender: TObject);
begin
TagListView.Items.Clear;
PreviewImage.Picture.Assign(nil);
ShellTreeViewGetImageIndex(nil, ShellTreeView.Selected);
FreeAndNil(FImgInfo);
UpdateCaption;
end;
*)
procedure TMainForm.TagListViewCompare(Sender: TObject; Item1, Item2: TListItem;
Data: Integer; var Compare: Integer);
var
tag1, tag2: TTag;
begin
tag1 := TTag(Item1.Data);
tag2 := TTag(Item2.Data);
Compare := CompareValue(ord(tag1.Group), ord(tag2.Group));
if Compare = 0 then
Compare := CompareText(Item1.SubItems[0], Item2.SubItems[0]);
end;
procedure TMainForm.TagListViewSelectItem(Sender: TObject; Item: TListItem;
Selected: Boolean);
const
{ TTagType:
ttUInt8 = 1, ttString, ttUInt16, ttUInt32, ttURational,
ttSInt8, ttBinary, ttSInt16, ttSInt32, ttSRational,
ttSingle, ttDouble,
ttIFD // rarely used, in Olympus maker notes
}
TAGTYPE_NAMES: array[TTagType] of string = (
'BYTE', 'ASCII', 'UINT16', 'UINT32', 'URATIONAL',
'SBYTE', 'BINARY', 'SINT16', 'SINT32', 'SRATIONAL',
'SINGLE', 'DOUBLE',
'IFD'
);
var
lTag: TTag;
s: String;
tagID: TTagIDRec;
begin
if Selected then begin
lTag := TTag(Item.Data);
if lTag <> nil then begin
tagID := TTagIDRec(lTag.TagID);
Statusbar1.Panels[0].Text := Format('ID %d [$%.4x]', [tagID.Tag, tagID.Tag]);
Statusbar1.Panels[1].Text := Format('Parent %d [$%.4x]', [tagID.Parent, tagID.Parent]);
Statusbar1.Panels[2].Text := 'Name: ' + lTag.Name;
Statusbar1.Panels[3].Text := 'Type: ' + TAGTYPE_NAMES[lTag.TagType];
Statusbar1.Panels[4].Text := 'Elements: ' + IntToStr(lTag.Count);
exit;
end;
end;
Statusbar1.Panels[0].Text := '';
Statusbar1.Panels[1].Text := '';
Statusbar1.Panels[2].Text := '';
Statusbar1.Panels[3].Text := '';
Statusbar1.Panels[4].Text := '';
end;
procedure TMainForm.UpdateCaption;
var
fn: String;
begin
if FImgInfo <> nil then
FileNameInfo.Caption := Format(
'File: %s' + LineEnding +
'Size: %d kB' + LineEnding +
'Date: %s', [
FImgInfo.Filename, FImgInfo.FileSize div 1024, DateTimeToStr(FImgInfo.FileDate)])
else
if FFilename <> '' then
FilenameInfo.Caption := Format('File: %s', [FFileName])
else
FilenameInfo.caption := '< no file >';
end;
end.