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

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 SaveToStream Image and Params
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

graphman

259 Posts

Posted - Oct 21 2013 :  15:24:40  Show Profile  Reply
Is there a way to saveto stream and load to stream image and params?

void __fastcall TForm8::ButtonSaveClick(TObject *Sender)
{
//test.dat exists and empty
TFileStream* fs = new TFileStream("C:\\TEMP1\\test.dat", fmOpenReadWrite|fmShareExclusive);
TIOFileType filetype;
filetype = FindFileFormat(OpenImageEnDialog1->FileName,false);
ImageEnIO1->StreamHeaders = true;
ImageEnIO1->SaveToStream(fs,filetype);
if (filetype != 1) ImageEnIO1->Params->SaveToStream(fs);
delete fs;
}
//---------------------------------------------------------------------------

void __fastcall TForm8::ButtonLoadClick(TObject *Sender)
{
TFileStream* fs = new TFileStream("C:\\TEMP1\\test.dat", fmOpenRead|fmShareDenyWrite);
fs->Position = 0;
ImageEnIO1->LoadFromStream(fs);
ImageEnIO1->Params->LoadFromStream(fs);
ImageEnVect1->Update();
delete fs;
}
//---------------------------------------------------------------------------


ERROR

xequte

39108 Posts

Posted - Oct 22 2013 :  20:02:21  Show Profile  Reply
Hi

You should not use StreamHeaders if you are saving a single image as that will make it incompatible with other applications.

Please try StreamHeaders = false;

Then test whether the created file can be opened in another image application.

Also, please clarify the nature of the error that you encounter.



Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page

graphman

259 Posts

Posted - Oct 23 2013 :  00:17:37  Show Profile  Reply
I need to save and load stream (image + params) in our program.
There is Error at loading.
Go to Top of Page

graphman

259 Posts

Posted - Oct 23 2013 :  00:19:47  Show Profile  Reply
In the previous version all was OK.
Go to Top of Page

xequte

39108 Posts

Posted - Oct 23 2013 :  02:02:19  Show Profile  Reply
OK, what is the error message? On what line does it occur?



Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page

graphman

259 Posts

Posted - Oct 23 2013 :  02:19:21  Show Profile  Reply
ButtonLoadClick
ImageEnIO1->Params->LoadFromStream(fs);
"out of memory"
Go to Top of Page

fab

1310 Posts

Posted - Oct 30 2013 :  03:55:51  Show Profile  Reply
Graphman, unfortunately it is not as simple as it seems. The decoder (jpeg, tiff...) could not read the stream from start to the end: so when LoadFromStream finishes the stream position may not be at the start of the "params".
You should use header streams for both read and write, and read manually this header in order to set the right position for the "params" stream.
Here is an example in Delphi:

// write a TIFF and Params
var
  fs: TFileStream;
begin
  fs := TFileStream.Create('c:\test.dat', fmCreate);
  ImageEnView1.IO.StreamHeaders := true;
  ImageEnView1.IO.SaveToStreamTIFF(fs);
  ImageEnView1.IO.Params.SaveToStream(fs);
  fs.Free();
end;

// read back the TIFF and Params
var
  fs: TFileStream;
  streamHeader: TIFFSHead;
begin
  fs := TFileStream.Create('c:\test.dat', fmOpenRead);
  fs.Read(streamHeader, sizeof(TIFFSHead));
  fs.Position := 0;
  ImageEnView1.IO.StreamHeaders := true;
  ImageEnView1.IO.LoadFromStreamTIFF(fs);
  fs.Position := streamHeader.dim + sizeof(TIFFSHead);
  ImageEnView1.Io.Params.LoadFromStream(fs);
  fs.Free();
end;


From next minor version this will be enough:
var
  fs: TFileStream;
begin
  fs := TFileStream.Create('c:\test.dat', fmOpenRead);
  ImageEnView1.IO.StreamHeaders := true;
  ImageEnView1.IO.LoadFromStreamTIFF(fs);
  ImageEnView1.Io.Params.LoadFromStream(fs);
  fs.Free();
end;


Hope this helps.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: