Author |
Topic  |
|
kandc

29 Posts |
Posted - Dec 09 2014 : 16:23:26
|
I have been struggling with a new problem this afternoon using ImageEnMView, Append and saving to Stream.
I load a tif into MView. All good.
I append a Tif, MView looks fine. I can even:
MView.MIO.SaveToFile ('x'); then open in windows, all is good.
But!
If I create a stream, save MView.MIO.SaveToStreamTiff, Position stream to 0, then Save the Stream to File, the images are out of order.
I have 3 separate tif files with one page each. Each tiff is identified by big numbers (1, 2 and 3).
Load page 1, all good. Load page 1, append page 2, the stream (MView itself is fine), saves the images as 2 then 1.
Load page 1, append page 2, append page 3, (again MView fine), saves the images as 3, 1, then 2.
I have debugged the code and found some strange stuff. When saving, it iterates through all the pages (0 through count - 1), saving each to the stream. However, when it writes to the stream, the first page is not inserted, the remaining pages are inserted at the beginning (it appears). I tried to change this behavior, but found it just messed the stream up.
The only thing I can think of is that the order of the pages is maintained separately the loading and when using append, then savetostream, things get out of order.
Kevin |
|
xequte
    
39140 Posts |
Posted - Dec 10 2014 : 01:58:36
|
Hi Kevin
I cannot see how you would be getting a different result between SaveToFileTIFF and SaveToStreamTIFF.
Here is the relevant code:
procedure TImageEnMIO.SaveToFileTIFF(const FileName: string; SelectedOnly: Boolean = False);
var
fs: TFileStream;
begin
fAborting := False;
fs := TFileStream.Create(FileName, fmCreate);
try
SaveToStreamTIFF(fs, SelectedOnly);
finally
FreeAndNil(fs);
end;
end;
So all SaveToFileTIFF is create a file stream and call SaveToStreamTIFF.
Can you show us the code you are using.
Nigel Xequte Software www.xequte.com nigel@xequte.com
|
 |
|
kandc

29 Posts |
Posted - Dec 10 2014 : 09:51:35
|
Finally figured it out. Requires: Application.ProcessMessages;
program SaveToFile;
uses
Vcl.Forms,
SaveToFileMain in 'SaveToFileMain.pas' {Form1};
{$R *.res}
begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
unit SaveToFileMain;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, ieopensavedlg, Vcl.StdCtrls,
Vcl.ExtCtrls, ieview, iemview;
type
TForm1 = class(TForm)
MView: TImageEnMView;
Panel1: TPanel;
bLoad: TButton;
bAppend: TButton;
OpenDialog: TOpenImageEnDialog;
cbProcessMessages: TCheckBox;
procedure OnClickLoad(Sender: TObject);
procedure OnClickAppend(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.OnClickAppend(Sender: TObject);
var
MS : TMemoryStream;
begin
if (OpenDialog.Execute) then
begin
MView.SelectedImage := MView.ImageCount - 1;
MView.LoadFromFileOnDemand (OpenDialog.FileName,True);
// Must processmessage, otherwise images out of order on save.
if (cbProcessMessages.Checked) then
Application.ProcessMessages;
MS := TMemoryStream.Create;
try
MView.MIO.SaveToStreamTiff (MS);
MS.Position := 0;
MS.SaveToFile ('c:\test\AfterAppend.tif');
finally
MS.Free;
end;
end;
end;
procedure TForm1.OnClickLoad(Sender: TObject);
var
MS : TMemoryStream;
begin
if (OpenDialog.Execute) then
begin
MView.Clear;
MView.LoadFromFileOnDemand (OpenDialog.FileName,False);
MS := TMemoryStream.Create;
try
MView.MIO.SaveToStreamTiff (MS);
MS.Position := 0;
MS.SaveToFile ('c:\test\AfterLoad.tif');
finally
MS.Free;
end;
end;
end;
end.
object Form1: TForm1
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 350
ClientWidth = 531
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object MView: TImageEnMView
Left = 0
Top = 41
Width = 531
Height = 309
Background = clBtnFace
ParentCtl3D = False
StoreType = ietNormal
ThumbWidth = 100
ThumbHeight = 100
HorizBorder = 4
VertBorder = 4
TextMargin = 0
GridWidth = 0
Style = iemsACD
ThumbnailsBackground = clBtnFace
ThumbnailsBackgroundSelected = clBtnFace
MultiSelectionOptions = []
ThumbnailsBorderWidth = 0
Align = alClient
TabOrder = 0
ExplicitWidth = 454
end
object Panel1: TPanel
Left = 0
Top = 0
Width = 531
Height = 41
Align = alTop
TabOrder = 1
ExplicitWidth = 454
object bLoad: TButton
Left = 16
Top = 8
Width = 121
Height = 25
Caption = '&Load'
TabOrder = 0
OnClick = OnClickLoad
end
object bAppend: TButton
Left = 143
Top = 8
Width = 114
Height = 25
Caption = '&Append'
TabOrder = 1
OnClick = OnClickAppend
end
object cbProcessMessages: TCheckBox
Left = 304
Top = 12
Width = 145
Height = 17
Caption = 'ProcessMessages'
TabOrder = 2
end
end
object OpenDialog: TOpenImageEnDialog
Filter =
'All Common Graphic Files|*.tif;*.tiff;*.fax;*.g3n;*.g3f;*.xif;*.' +
'gif;*.jpg;*.jpeg;*.jpe;*.jif;*.pcx;*.bmp;*.dib;*.rle;*.ico;*.cur' +
';*.png;*.dcm;*.dic;*.dicom;*.v2;*.wmf;*.emf;*.tga;*.targa;*.vda;' +
'*.icb;*.vst;*.pix;*.pxm;*.ppm;*.pgm;*.pbm;*.wbmp;*.jp2;*.j2k;*.j' +
'pc;*.j2c;*.dcx;*.crw;*.cr2;*.nef;*.raw;*.pef;*.raf;*.x3f;*.bay;*' +
'.orf;*.srf;*.mrw;*.dcr;*.sr2;*.psd;*.psb;*.iev;*.lyr;*.all;*.wdp' +
';*.hdp;*.jxr;*.avi;*.mpeg;*.mpg;*.wmv|All Files (*.*)|*.*|JPEG B' +
'itmap (*.jpg;*.jpeg;*.jpe;*.jif)|*.jpg;*.jpeg;*.jpe;*.jif|TIFF B' +
'itmap (*.tif;*.tiff;*.fax;*.g3n;*.g3f;*.xif)|*.tif;*.tiff;*.fax;' +
'*.g3n;*.g3f;*.xif|CompuServe Bitmap (*.gif)|*.gif|PaintBrush (*.' +
'pcx)|*.pcx|Windows Bitmap (*.bmp;*.dib;*.rle)|*.bmp;*.dib;*.rle|' +
'Windows Icon (*.ico)|*.ico|Windows Cursor (*.cur)|*.cur|Portable' +
' Network Graphics (*.png)|*.png|DICOM Bitmap (*.dcm;*.dic;*.dico' +
'm;*.v2)|*.dcm;*.dic;*.dicom;*.v2|Windows Metafile (*.wmf)|*.wmf|' +
'Enhanced Windows Metafile (*.emf)|*.emf|Targa Bitmap (*.tga;*.ta' +
'rga;*.vda;*.icb;*.vst;*.pix)|*.tga;*.targa;*.vda;*.icb;*.vst;*.p' +
'ix|Portable Pixmap, GrayMap, BitMap (*.pxm;*.ppm;*.pgm;*.pbm)|*.' +
'pxm;*.ppm;*.pgm;*.pbm|Wireless Bitmap (*.wbmp)|*.wbmp|JPEG2000 (' +
'*.jp2)|*.jp2|JPEG2000 Code Stream (*.j2k;*.jpc;*.j2c)|*.j2k;*.jp' +
'c;*.j2c|Multipage PCX (*.dcx)|*.dcx|Camera RAW (*.crw;*.cr2;*.ne' +
'f;*.raw;*.pef;*.raf;*.x3f;*.bay;*.orf;*.srf;*.mrw;*.dcr;*.sr2)|*' +
'.crw;*.cr2;*.nef;*.raw;*.pef;*.raf;*.x3f;*.bay;*.orf;*.srf;*.mrw' +
';*.dcr;*.sr2|Photoshop PSD (*.psd;*.psb)|*.psd;*.psb|Vectorial o' +
'bjects (*.iev)|*.iev|Layers (*.lyr)|*.lyr|Layers and objects (*.' +
'all)|*.all|Microsoft HD Photo (*.wdp;*.hdp;*.jxr)|*.wdp;*.hdp;*.' +
'jxr|Video for Windows (*.avi)|*.avi|MPEG (*.mpeg;*.mpg)|*.mpeg;*' +
'.mpg|Windows Media Video (*.wmv)|*.wmv'
Left = 256
Top = 73
end
end
|
 |
|
kandc

29 Posts |
Posted - Dec 10 2014 : 09:54:57
|
> I cannot see how you would be getting a different result between SaveToFileTIFF and SaveToStreamTIFF.
Because I added a debug button to savetofile, which caused Processing.
|
 |
|
xequte
    
39140 Posts |
Posted - Dec 10 2014 : 12:39:08
|
Hi
The issue here appears to be that you are using LoadFromFileOnDemand to load the images. This loads it as it is needed onscreen, so the frame may not even be ready at the time you save. You should use LoadFromFile instead.
Nigel Xequte Software www.xequte.com nigel@xequte.com
|
 |
|
kandc

29 Posts |
Posted - Dec 10 2014 : 13:13:02
|
I used LoadfromFileOnDemand because it has the Append option. LoadFromFile does not offer an Append parameter. How do you use LoadFromFile to append additional images?
Thanks!
Kevin |
 |
|
xequte
    
39140 Posts |
Posted - Dec 11 2014 : 15:04:20
|
Hi Kevin
Actually after investigation, this appears to be a bug. We will look into this.
Nigel Xequte Software www.xequte.com nigel@xequte.com
|
 |
|
kandc

29 Posts |
Posted - Dec 11 2014 : 15:53:37
|
Thanks Nigel!! |
 |
|
xequte
    
39140 Posts |
|
|
Topic  |
|
|
|