BSOne.SFC/EM.Lib/ImageEn_SRC/Demos/InputOutput/XMP/umain.pas

177 lines
4.8 KiB
Plaintext

unit umain;
{$WARN UNIT_PLATFORM OFF}
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, Grids, ieview, ImageEnView,
FileCtrl, StdCtrls, ImageEnIO, ComCtrls, ExtCtrls, hyieutils, hyiedefs, math, iexBitmaps, iesettings,
iexLayers, iexRulers;
type
TMainForm = class(TForm)
StringGrid1: TStringGrid;
Panel2: TPanel;
ImageEnView1: TImageEnView;
ProgressBar1: TProgressBar;
DriveComboBox1: TDriveComboBox;
DirectoryListBox1: TDirectoryListBox;
FileListBox1: TFileListBox;
OpenDialog1: TOpenDialog;
SaveDialog1: TSaveDialog;
lblMethod: TLabel;
cmbMethod: TComboBox;
procedure FormCreate(Sender: TObject);
procedure FileListBox1Change(Sender: TObject);
procedure ImageEnView1Progress(Sender: TObject; per: Integer);
procedure cmbMethodChange(Sender: TObject);
private
{ Private declarations }
procedure UpdateDisplay;
// Use standard TImageEnIO.Params properties
procedure ReadParameters_Method1;
// Use helper methods in iexMetaHelpers
procedure ReadParameters_Method2;
public
{ Public declarations }
end;
var
MainForm: TMainForm;
implementation
uses
iexMetaHelpers;
{$R *.DFM}
{$R WindowsTheme.res}
const
// Items of cmbMethod
_ieStandardImageEnProperties = 0;
_ieMetaHelperMethods = 1;
procedure TMainForm.FormCreate(Sender: TObject);
begin
IEAutoLoadIOPlugins;
FileListBox1.Mask := XMP_COMPATIBLE_EXTENSIONS;
cmbMethod.ItemIndex := _ieMetaHelperMethods;
end;
procedure TMainForm.FileListBox1Change(Sender: TObject);
begin
UpdateDisplay;
end;
// File selection has changed. Load XMP data
procedure TMainForm.UpdateDisplay;
begin
if IsKnownFormat(FileListBox1.FileName) then
begin
// load only parameters
ImageEnView1.IO.ParamsFromFile(FileListBox1.FileName);
if assigned(ImageEnView1.IO.Params.EXIF_Bitmap) and not ImageEnView1.IO.Params.EXIF_Bitmap.IsEmpty then
begin
// there is a thumbnail, display it
ImageEnView1.IEBitmap.Assign( ImageEnView1.IO.Params.EXIF_Bitmap );
ImageEnView1.Update;
end
else
begin
// we need only a thumbnail (fast load)
ImageEnView1.IO.Params.GetThumbnail:=true;
ImageEnView1.io.LoadFromFile(FileListBox1.FileName);
end;
ProgressBar1.Position := 0;
case cmbMethod.ItemIndex of
_ieStandardImageEnProperties : ReadParameters_Method1;
_ieMetaHelperMethods : ReadParameters_Method2;
end;
end
else
begin
ImageEnView1.Blank;
StringGrid1.ClearGridFields;
end;
end;
// Loading progress
procedure TMainForm.ImageEnView1Progress(Sender: TObject; per: Integer);
begin
ProgressBar1.Position := per;
end;
procedure TMainForm.ReadParameters_Method1;
const
XMP_Prop_Count = 11;
function _GetXmpString(const sProp: string) : string;
begin
try
Result := ImageEnView1.IO.Params.Dict.GetDictionary( 'XMP' ).GetString( sProp );
except
Result := '';
end;
end;
function _GetXmpDateTime(const sProp: string) : TDateTime;
begin
try
// XMP date string values are the same as EXIF
Result := EXIFDateToDateTime( ImageEnView1.IO.Params.Dict.GetDictionary( 'XMP' ).GetString( sProp ));
except
Result := 0;
end;
end;
begin
// initialize properties grid
StringGrid1.RowCount := StringGrid1.FixedRows + XMP_Prop_Count;
StringGrid1.Cells[0, 0] := 'Property name';
StringGrid1.Cells[1, 0] := 'Value';
with ImageEnView1.IO.Params do
begin
StringGrid1.Cells[0, 1] := 'Description';
StringGrid1.Cells[1, 1] := _GetXmpString( 'dc:description' );
StringGrid1.Cells[0, 2] := 'Creation Date';
StringGrid1.Cells[1, 2] := DateTimeToStr( _GetXmpDateTime( 'xmp:CreateDate' ));
StringGrid1.Cells[0, 3] := 'Creator';
StringGrid1.Cells[1, 3] := _GetXmpString( 'dc:creator' );
StringGrid1.Cells[0, 4] := 'City';
StringGrid1.Cells[1, 4] := _GetXmpString( 'photoshop:City' );
StringGrid1.Cells[0, 5] := 'State';
StringGrid1.Cells[1, 5] := _GetXmpString( 'photoshop:State' );
StringGrid1.Cells[0, 6] := 'Country';
StringGrid1.Cells[1, 6] := _GetXmpString( 'photoshop:Country' );
StringGrid1.Cells[0, 7] := 'Title';
StringGrid1.Cells[1, 7] := _GetXmpString( 'dc:title' );
StringGrid1.Cells[0, 8] := 'Keywords';
StringGrid1.Cells[1, 8] := _GetXmpString( 'dc:subject' );
StringGrid1.Cells[0, 9] := 'Copyright';
StringGrid1.Cells[1, 9] := _GetXmpString( 'dc:rights' );
StringGrid1.Cells[0, 10] := 'Headline';
StringGrid1.Cells[1, 10] := _GetXmpString( 'photoshop:Headline' );
StringGrid1.Cells[0, 11] := 'Rating';
StringGrid1.Cells[1, 12] := _GetXmpString( 'xmp:Rating' );
end;
end;
procedure TMainForm.ReadParameters_Method2;
begin
StringGrid1.ReadGridFromXMP(ImageEnView1.IO.Params);
end;
procedure TMainForm.cmbMethodChange(Sender: TObject);
begin
UpdateDisplay;
end;
end.