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
 Save and Load from stream.
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

jbspcr

USA
2 Posts

Posted - Feb 05 2016 :  09:39:07  Show Profile  Reply
When I try this code, image2 never shows the image loaded into the stream from image1.

ms:= TMemoryStream.Create;
image1.IO.LoadFromFile('boy.jpg');
image1.IO.SaveToStream(ms,ioUnknown);
ms.Position:= 0;
image2.IO.LoadFromStream(ms,ioUnknown);
ms.Free;

If I change the FileType parameter to "ioJPEG" works as expected.

ms:= TMemoryStream.Create;
image1.IO.LoadFromFile('boy.jpg');
image1.IO.SaveToStream(ms,ioJPEG);
ms.Position:= 0;
image2.IO.LoadFromStream(ms,ioJPEG);
ms.Free;

Is there a way to use ioUnknown in this situation in the case where the input image file type is a range of types? png, jpg, bmp etc..

Great tools, thanks!

w2m

USA
1990 Posts

Posted - Feb 05 2016 :  09:46:14  Show Profile  Reply
I have not tried this, but try setting the SreamHeaders property to true.

function LoadFromStream(Stream: TStream; FileFormat: TIOFileType = ioUnknown): Boolean;

Load an image from the specified stream into the attached TImageEnView or TIEBitmap. If FileFormat is ioUnknown the file format is detected by reading the image header (using FindStreamFormat).
The result will be false if an error is encountered, e.g. the file in the stream is not a recognized format (Aborting will be true).

If the StreamHeaders property is True, the stream must have a special header (saved with SaveToStream).

Bill Miller
Adirondack Software & Graphics
Email: w2m@hughes.net
EBook: http://www.imageen.com/ebook/
Custom Commercial ImageEn Development
Go to Top of Page

jbspcr

USA
2 Posts

Posted - Feb 05 2016 :  10:21:34  Show Profile  Reply
Thanks for the fast reply.

I changed the code to include the StreamHeaders flag. Image2 still doesn't show the image. Any other ideas?

ms:= TMemoryStream.Create;
image1.IO.StreamHeaders:= True;
image1.IO.LoadFromFile('boy.jpg');
image1.IO.SaveToStream(ms,ioUnknown);
ms.Position:= 0;
image2.IO.StreamHeaders:= True;
image2.IO.LoadFromStream(ms,ioUnknown);
image2.Update;

I realize I could set the file type based on the file extension, just thought it would be better to let the IO handle this operation.

thanks.
Go to Top of Page

w2m

USA
1990 Posts

Posted - Feb 05 2016 :  10:23:27  Show Profile  Reply
Sorry. I do not have ay other ideas except maybe
image2.IO.LoadFromStream(ms, ioJPEG); This may work but could fail also.

Bill Miller
Adirondack Software & Graphics
Email: w2m@hughes.net
EBook: http://www.imageen.com/ebook/
Custom Commercial ImageEn Development
Go to Top of Page

wesleybobato

Brazil
367 Posts

Posted - Feb 05 2016 :  13:08:43  Show Profile  Reply
procedure TForm1.BitBtn1Click(Sender: TObject);
var
Ms: TMemoryStream;
FileType: Integer;
begin
Ms := TMemoryStream.Create;
try
image1.IO.LoadFromFile( 'C:\Users\Public\Pictures\Sample Pictures\Koala.jpg' );
image1.IO.SaveToStream( Ms, ioJPEG );

Ms.Position := 0;
FileType := FindStreamFormat( Ms );
image2.IO.StreamHeaders := True;
image2.IO.LoadFromStream( Ms, FileType );

finally
FreeandNil( ms );
end;

end;
Go to Top of Page

w2m

USA
1990 Posts

Posted - Feb 05 2016 :  13:27:47  Show Profile  Reply
All of these streaming code works as expected. Tested with ImageEn 6.x. No problems here.

procedure TForm1.Clear1Click(Sender: TObject);
begin
  ImageEnView2.Clear;
end;

procedure TForm1.Open1Click(Sender: TObject);
begin
  if OpenImageEnDialog1.Execute then
  begin
    ImageEnView1.IO.LoadFromFile(OpenImageEnDialog1.FileName);
    ImageEnView1.Fit();
  end;
end;

procedure TForm1.Stream1Click(Sender: TObject);
var
  iMs: TMemoryStream;
begin
  iMs := TMemoryStream.Create;
  try
    ImageEnView1.IO.StreamHeaders := True;
    ImageEnView1.IO.SaveToStream(iMs, ioTIFF);
    iMs.Position := 0;
    ImageEnView2.IO.StreamHeaders := True;
    ImageEnView2.IO.LoadFromStream(iMs, ioTIFF);
    ImageEnView2.Fit();
    ImageEnView2.Update; Important!!
  finally
    iMs.Free;
  end;
end;

procedure TForm1.Stream2Click(Sender: TObject);
{Wesley Method}
var
  iMs: TMemoryStream;
  iFileType: Integer;
begin
  iMs := TMemoryStream.Create;
  try
    ImageEnView1.IO.StreamHeaders := True;
    ImageEnView1.IO.SaveToStream(iMs, ioTIFF);
    iMs.Position := 0;
    iFileType := FindStreamFormat(iMs);
    ImageEnView2.IO.StreamHeaders := True;
    ImageEnView2.IO.LoadFromStream(iMs, iFileType);
    ImageEnView2.Fit();
    ImageEnView2.Update; Important!! 
  finally
    iMs.Free;
  end;
end;

procedure TForm1.Stream3Click(Sender: TObject);
var
  iMs: TMemoryStream;
begin
  iMs := TMemoryStream.Create;
  try
    ImageEnView1.IO.SaveToStream(iMs, ioTIFF);
    iMs.Position := 0;
    ImageEnView2.IO.LoadFromStream(iMs, ioTIFF);
    ImageEnView2.Fit();
    ImageEnView2.Update;
  finally
    iMs.Free;
  end;
end;

Bill Miller
Adirondack Software & Graphics
Email: w2m@hughes.net
EBook: http://www.imageen.com/ebook/
Custom Commercial ImageEn Development
Go to Top of Page

xequte

38944 Posts

Posted - Feb 06 2016 :  03:59:16  Show Profile  Reply
Hi

You must pass a format to SaveToStream, you cannot use ioUnknown. If you want to use the current format use:

image1.IO.LoadFromFile( 'boy.jpg' );
image1.IO.SaveToStream( ms, image1.IO.Params.FileType );


Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: