ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 rotating and saving pages in multi-page TIFF

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

View 
UserName:
Password:
Format  Bold Italicized Underline  Align Left Centered Align Right  Horizontal Rule  Insert Hyperlink   Browse for an image to attach to your post Browse for a zip to attach to your post Insert Code  Insert Quote Insert List
   
Message 

 

Emoji
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Black Eye [B)]
Frown [:(] Shocked [:0] Angry [:(!] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
dave.sellers Posted - Dec 31 2013 : 03:16:20
Hi

This feels like it should be simple but I'm struggling somewhat. I have a multi-page TIFF and I want to rotate some of the pages. I feel sure there ought to be a way of just opening the file, rotating the necessary pages and then saving the changes but I cannot seem to find it.

Using a TImageEnView and a TIETIFFHandler I have been able to load each page into the TImageEnView, rotate if necessary and then add each page to a NEW temporary file with TIETIFFHandler.InsertPageAsImage then I can delete the original file and rename the temp file but this seems such a complicated way to go about it that it must be wrong.

Can anybody put me out of my misery and point me in the right direction?

Many thanks in advance.
Dave
7   L A T E S T    R E P L I E S    (Newest First)
w2m Posted - Jul 15 2014 : 12:40:16
As Nigel pointed out if you have StoreType set to ietThumb then only a thumbnail of the full image is stored in TImageEnMView and if you have StoreType set to ietNormal the full original image is stored.

But if you have StoreType set to ietThumb then another way to display the full image in TImageEnView you can get the filename from the thumbnail and then use TImageEnMView.IO.LoadFromFile to load the original image.
procedure TForm1.ImageEnMView1ImageSelect(Sender: TObject; Idx: Integer);
{ Display the image in ImageEnView. }
var
  iFilename: string;
begin
  if Idx <> -1 then
  begin
    ImageEnView1.IO.LoadFromFileJpeg(ImageEnMView1.MIO.Params[Idx].FileName);
    { Get the filename from the thumbnail }
    iFilename := ImageEnMView1.MIO.Params[iIndex].FileName;
    ImageEnView1.IO.LoadFromFile(iFilename);
   end;
end;

If you have StoreType set to ietNormal then you can use ImageEnMView1.GetTIEBitmap to get the original bitmap because the original image is stored in TImageEnMView.

Bill Miller
Adirondack Software & Graphics
Email: w2m@hughes.net
EBook: http://www.imageen.com/ebook/
Custom Commercial ImageEn Development
xequte Posted - Jul 15 2014 : 10:18:21
Hi Choukri

1. Please see the "TIFF Editor" demo which is in the "Image Editing" demos folder

2. If you are using the bitmaps of a TImageEnMView then you need to ensure the StoreType is ietNormal:

http://www.imageen.com/help/TImageEnMView.StoreType.html



Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
chouk Posted - Jul 14 2014 : 08:42:08
Hi,

I have another problem when i scan a new Tiff file and load it with
ImageEnMView1.MIO.LoadFromFile(AFilename), when i use
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;

I get a bad image quality in the screen (ImageEnView)




The file is OK, the problem occur only on the screen even with the rotate button, what is the problem ?

Thank's for help

Choukri
chouk Posted - Jul 14 2014 : 07:24:01
Hi,

Is it possible to add an external file (jpeg, png...) in the current TIFF file and update ImageEnMView1 ? if yes how to do this ?

Regards,
Choukri
dave.sellers Posted - Jan 03 2014 : 07:33:14
Thanks William, the glaringly obvious eluded (again!)

Regards
Dave
w2m Posted - Dec 31 2013 : 12:55:44
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
dave.sellers Posted - Dec 31 2013 : 08:49:02
OK, I've improved on that, I now load both the TImageEnView and TIETIFFHandler from the same TFileStream. If a page needs rotating I load it into the TImageEnView from the stream, rotate as required then:

myTIFFHandler.DeletePage(x);
myTIFFHandler.InsertPageAsImage(ImageEnView1, x);
myStream.Position := 0;
myTIFFHandler.WriteStream(FR);

This seems to work quite well though I'd still welcome any other suggestions if there's a better (AKA faster) way

Dave