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
 Using SaveSelectionToStream
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

JensFudge

Denmark
8 Posts

Posted - Sep 01 2011 :  06:20:39  Show Profile  Reply
Hi

I am wondering why there isnt a SaveSelectionToStreamJpeg method..

Basically this is what I am trying to accomplish:

aStream := TMemoryStream.Create;
if ImageEnView1.Selected then
ImageEnView1.SaveSelectionToStream(aStream)
else
ImageEnView1.io.SaveToStreamJpeg(aStream);

The stream I will later add to a Blobfield in a database.
It works perfectly with SaveToStreamJpeg, but I get garbage using SaveSelectionToStream.

I have set the MouseInteract.select to true

How would one accomplish this?

Thanks for a great set of components!!

Jens Fudge

fab

1310 Posts

Posted - Sep 01 2011 :  06:44:21  Show Profile  Reply
Hi,
there isn't a method to save the selected area directly to a file or stream.

SaveSelectionToStream saves the selection data (coordinates, etc...) but not the selected pixels.

For this reason it is necessary to use a temporary buffer to contain the selected area. There are several ways to do it. The simplest is to use Undo mechanism:

// note: CropSel() returns the whole image when no selection exists
ImageEnView1.Proc.CropSel();
ImageEnView1.IO.SaveToStreamJpeg(aStream);
ImageEnView1.Proc.Undo();

Another way uses a temporary TIEBitmap (here named "bmp"):
if ImageEnView1.Selected then
begin
  bmp := TIEBitmap.Create(ImageEnView1.SelectedRect.width, ImageEnView1.SelectedRect.height);
  ImageEnView1.CopySelectionToIEBitmap(bmp);
  bmp.Write(aStream, ioJPEG);
  bmp.free;
end;

note1: exceptions handling not shown.
note2: ioJPEG defined in imageenio unit.

Go to Top of Page

JensFudge

Denmark
8 Posts

Posted - Sep 06 2011 :  06:36:19  Show Profile  Reply
Thanks, worked perfectly

Jens Fudge
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: