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
 Save and Load from stream.

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
jbspcr Posted - Feb 05 2016 : 09:39:07
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!
6   L A T E S T    R E P L I E S    (Newest First)
xequte Posted - Feb 06 2016 : 03:59:16
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
w2m Posted - Feb 05 2016 : 13:27:47
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
wesleybobato Posted - Feb 05 2016 : 13:08:43
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;
w2m Posted - Feb 05 2016 : 10:23:27
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
jbspcr Posted - Feb 05 2016 : 10:21:34
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.
w2m Posted - Feb 05 2016 : 09:46:14
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