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
 Free Stream after ImageEnMView.SetImageFromStream
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

Ralf

120 Posts

Posted - Feb 06 2017 :  10:11:02  Show Profile  Reply
Hello,

i tried following:

ImageEnMView.SetImageFromStream(idx, ImageStream);
ImageStream.free;

When i have a little Image every thing is ok. When it is a little bigger the Image is not showed in the ImageEnMView. When i don't make ImageStream.free it is displayed correct.

I thought SetImageFromStream make "copy" of the image and i can free the stream.

Thanks
Ralf

xequte

39053 Posts

Posted - Feb 06 2017 :  22:54:00  Show Profile  Reply
Hi Ralf

I cannot see any reason that would fail. Can you give me some example code to reproduce?


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

Ralf

120 Posts

Posted - Feb 07 2017 :  02:11:22  Show Profile  Reply
Hi Nigel,

what we do is following:
We use the ImageEnMView as preview in our own Document select/open Dialog.

What we make is not difficult. We only

function TDokPrivFrame.InsertThumb(Const fThumb: TIMageEnMView; Var aStream: TMemoryStream): Boolean;
begin
  Result:=ImageEnMView_AppendImage(fThumb,aStream)<>-1;
  FreeAndNil(aStream); 
end;

Here you see the subfunctions.

function ImageEnMView_InsertImageEx(Const ImageMEV: TImageEnMView; SelectIt:Boolean=false):Integer;
begin
  with ImageMEV do
  begin
    result:=ImageCount;
    if SelectIt then InsertImageEx(Result, imsAlways) 
    else             InsertImageEx(Result, imsAuto);  
  end;
end;

function  ImageEnMView_AppendImage (Const ImageMEV: TImageEnMView; ImageStream: TMemoryStream; SelectIt: Boolean=false): Integer; overload;
begin
  Result:=ImageEnMView_InsertImageEx(ImageMEV, SelectIt);
  ImageStream.Position:=0;
  ImageMEV.SetImageFromStream(Result, ImageStream);
end;

The special is, that we call the function to insert the Image inside a Thread. The error didn't happen with every image. To me is seems like it have something to do with the size of the image. May be the Thread also is involved.

Thanks
Ralf
Go to Top of Page

xequte

39053 Posts

Posted - Feb 07 2017 :  04:45:01  Show Profile  Reply
Hi Ralf

So it only happens when you run this code within a thread? It doesn't happen in a simple demo?



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

Ralf

120 Posts

Posted - Feb 07 2017 :  04:51:31  Show Profile  Reply
Hi Nigel,
i also tried without a Thread calling the insert code direct only with a timer between.

Regards

Ralf
Go to Top of Page

xequte

39053 Posts

Posted - Feb 09 2017 :  21:05:09  Show Profile  Reply
Hi Ralf

I tested as follows without error (Timer.interval was set to 5):


function ImageEnMView_InsertImageEx(Const ImageMEV: TImageEnMView; SelectIt:Boolean=false):Integer;
begin
  with ImageMEV do
  begin
    result:=ImageCount;
    if SelectIt then InsertImageEx(Result, imsAlways)
    else             InsertImageEx(Result, imsAuto);
  end;
end;

function  ImageEnMView_AppendImage(Const ImageMEV: TImageEnMView; ImageStream: TStream; SelectIt: Boolean=false): Integer; overload;
begin
  Result:=ImageEnMView_InsertImageEx(ImageMEV, SelectIt);
  ImageStream.Position:=0;
  ImageMEV.SetImageFromStream(Result, ImageStream);
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
  fs: TIEWideFileStream;
  idx: Integer;
begin
  fs := TIEWideFileStream.Create('D:\Lingari.jpg', fmOpenRead or fmShareDenyWrite);
  idx := ImageEnMView_AppendImage(ImageEnMView1, fs);
  if idx <> -1 then
    Caption := IntToStr( idx )
  else
    raise Exception.create( 'Error' );
  FreeAndNil(fs);
end;


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: