The simplest and fastest way to accomplish your task is to use a TImageEnMView to hold your images. Load the muiti-frame tif file with ImageEnMView1.MIO.LoadFromFile(AFilename). To rotate a selected image call ImageEnMView1.Proc.Rotate(90); Then save the image with ImageEnMView1.MIO.SaveToFile(AFilename);
When you use a TImageEnMView the multi-frame tif image frames are auomatically loaded and saved with no special attention needed. The added benefit is you do not have to use a TIETIFHandler at all... and when you rotate an image in ImageEnMView then select the image it will be rotated in ImageEnView as well.
Loading, rotating and saving the multi-frame tif file can be written with about 140 lines of code.
Here is the DFM file:
object Form1: TForm1
Left = 0
Top = 0
Caption = 'TIFFHandler'
ClientHeight = 299
ClientWidth = 635
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
OnDestroy = FormDestroy
PixelsPerInch = 96
TextHeight = 13
object Splitter1: TSplitter
Left = 203
Top = 41
Width = 5
Height = 198
ResizeStyle = rsUpdate
ExplicitLeft = 180
end
object Panel1: TPanel
Left = 0
Top = 0
Width = 635
Height = 41
Align = alTop
BevelOuter = bvNone
TabOrder = 0
DesignSize = (
635
41)
object Close1: TButton
Left = 549
Top = 7
Width = 75
Height = 25
Anchors = [akTop, akRight]
Caption = 'Close'
TabOrder = 0
OnClick = Close1Click
end
object Open1: TButton
Left = 12
Top = 10
Width = 75
Height = 25
Caption = 'Open'
TabOrder = 1
OnClick = Open1Click
end
object Save1: TButton
Left = 93
Top = 10
Width = 75
Height = 25
Caption = 'Save'
TabOrder = 2
OnClick = Save1Click
end
object SaveAs1: TButton
Left = 174
Top = 10
Width = 75
Height = 25
Caption = 'SaveAs'
TabOrder = 3
OnClick = SaveAs1Click
end
object Rotate1: TButton
Left = 255
Top = 10
Width = 75
Height = 25
Caption = 'Rotate'
TabOrder = 4
OnClick = Rotate1Click
end
end
object Panel2: TPanel
Left = 0
Top = 239
Width = 635
Height = 41
Align = alBottom
BevelOuter = bvNone
TabOrder = 1
DesignSize = (
635
41)
object Close2: TButton
Left = 549
Top = 8
Width = 75
Height = 25
Anchors = [akTop, akRight]
Caption = 'Close'
TabOrder = 0
OnClick = Close1Click
end
end
object StatusBar1: TStatusBar
Left = 0
Top = 280
Width = 635
Height = 19
Panels = <>
end
object ImageEnMView1: TImageEnMView
Left = 0
Top = 41
Width = 203
Height = 198
Background = clBtnFace
ParentCtl3D = False
StoreType = ietNormal
ThumbWidth = 100
ThumbHeight = 100
HorizBorder = 4
VertBorder = 4
TextMargin = 0
OnImageSelect = ImageEnMView1ImageSelect
GridWidth = 1
Style = iemsACD
ThumbnailsBackground = clBtnFace
ThumbnailsBackgroundSelected = clBtnFace
EnableMultiSelect = True
MultiSelectionOptions = []
ThumbnailsBorderWidth = 0
Align = alLeft
PopupMenu = PopupMenu1
TabOrder = 3
end
object ImageEnView1: TImageEnView
Left = 208
Top = 41
Width = 427
Height = 198
Background = clBtnFace
ParentCtl3D = False
EnableInteractionHints = True
Align = alClient
TabOrder = 4
end
object OpenPictureDialog1: TOpenPictureDialog
Left = 12
Top = 244
end
object SavePictureDialog1: TSavePictureDialog
Left = 41
Top = 245
end
object ImageEnProc1: TImageEnProc
PreviewsParams = [prppShowResetButton, prppHardReset]
PreviewFont.Charset = DEFAULT_CHARSET
PreviewFont.Color = clWindowText
PreviewFont.Height = -11
PreviewFont.Name = 'Tahoma'
PreviewFont.Style = []
Left = 72
Top = 246
end
object ImageEnIO1: TImageEnIO
PreviewFont.Charset = DEFAULT_CHARSET
PreviewFont.Color = clWindowText
PreviewFont.Height = -11
PreviewFont.Name = 'Tahoma'
PreviewFont.Style = []
Left = 101
Top = 247
end
object ImageEnMIO1: TImageEnMIO
PreviewFont.Charset = DEFAULT_CHARSET
PreviewFont.Color = clWindowText
PreviewFont.Height = -11
PreviewFont.Name = 'Tahoma'
PreviewFont.Style = []
Left = 131
Top = 247
end
object PopupMenu1: TPopupMenu
Left = 160
Top = 247
object Delete1: TMenuItem
Caption = 'Delete'
OnClick = Delete1Click
end
object Rotate2: TMenuItem
Caption = 'Rotate'
OnClick = Rotate1Click
end
end
end
Here is the code:
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
Vcl.ExtCtrls, Vcl.ExtDlgs, Vcl.StdCtrls, Vcl.ComCtrls,
iemio, imageenio, imageenproc, hyiedefs, hyieutils, imageenview, ieview,
iemview, Vcl.Menus;
type
TForm1 = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
StatusBar1: TStatusBar;
Close1: TButton;
Close2: TButton;
OpenPictureDialog1: TOpenPictureDialog;
SavePictureDialog1: TSavePictureDialog;
Open1: TButton;
Save1: TButton;
SaveAs1: TButton;
ImageEnMView1: TImageEnMView;
Splitter1: TSplitter;
ImageEnView1: TImageEnView;
ImageEnProc1: TImageEnProc;
ImageEnIO1: TImageEnIO;
ImageEnMIO1: TImageEnMIO;
Rotate1: TButton;
PopupMenu1: TPopupMenu;
Delete1: TMenuItem;
Rotate2: TMenuItem;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Open1Click(Sender: TObject);
procedure SaveAs1Click(Sender: TObject);
procedure Close1Click(Sender: TObject);
procedure ImageEnMView1ImageSelect(Sender: TObject; idx: Integer);
procedure Rotate1Click(Sender: TObject);
procedure Delete1Click(Sender: TObject);
procedure Save1Click(Sender: TObject);
private
{ Private declarations }
AFilename: string;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Close1Click(Sender: TObject);
begin
Close;
end;
procedure TForm1.Delete1Click(Sender: TObject);
var
i: Integer;
begin
for i := 0 to ImageEnMView1.MultiSelectedImagesCount - 1 do
begin
ImageEnMView1.DeleteImage(i);
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
AFilename := '';
IERegisterFormats;
OpenPictureDialog1.Filter := GraphicFilter(TGraphic);
SavePictureDialog1.Filter := GraphicFilter(TGraphic);
ImageEnMView1.SetModernStyling(True, 150, 100);
ATIFHandler := TIETIFFHandler.Create;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
IEUnRegisterFormats;
end;
procedure TForm1.ImageEnMView1ImageSelect(Sender: TObject; idx: Integer);
var
iIEBitmap: TIEBitmap;
begin
iIEBitmap := ImageEnMView1.GetTIEBitmap(idx);
try
ImageEnView1.IEBitmap.Assign(iIEBitmap);
ImageEnView1.Update;
finally
ImageEnMView1.ReleaseBitmap(idx);
end;
end;
procedure TForm1.Open1Click(Sender: TObject);
begin
OpenPictureDialog1.DefaultExt := '.tif';
if OpenPictureDialog1.Execute then
begin
if FileExists(OpenPictureDialog1.FileName) then
begin
AFilename := OpenPictureDialog1.FileName;
ImageEnMView1.MIO.LoadFromFile(AFilename);
Caption := 'TIFFHandler- ' + AFilename;
end;
end;
end;
procedure TForm1.Rotate1Click(Sender: TObject);
var
iIndex: Integer;
iIEBitmap: TIEBitmap;
begin
iIndex := ImageEnMView1.SelectedImage;
ImageEnMView1.Proc.Rotate(90);
iIEBitmap := ImageEnMView1.GetTIEBitmap(iIndex);
try
ImageEnView1.IEBitmap.Assign(iIEBitmap);
ImageEnView1.Update;
finally
ImageEnMView1.ReleaseBitmap(iIndex);
end;
end;
procedure TForm1.Save1Click(Sender: TObject);
begin
if FileExists(AFilename) then
ImageEnMView1.MIO.SaveToFile(AFilename);
end;
procedure TForm1.SaveAs1Click(Sender: TObject);
begin
SavePictureDialog1.DefaultExt := '.tif';
if SavePictureDialog1.Execute then
begin
AFilename := SavePictureDialog1.FileName;
ImageEnMView1.MIO.SaveToFile(AFilename);
Caption := 'TIFFHandler- ' + AFilename;
end;
end;
end.
William Miller
Adirondack Software & Graphics
Email: w2m@frontiernet.net
EBook: http://www.imageen.com/ebook/
Apprehend: http://www.frontiernet.net/~w2m/index.html