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
 About TImageEnMView's LoadFromFileOnDemand
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

Flashcqxg

115 Posts

Posted - Apr 21 2025 :  01:28:53  Show Profile  Reply
I want to download images from a server, load them into TImageEnMView, and then use CopyToIEBitmap to view and edit them in TImageEnView.
To speed up the process, I download the image stream from the server to the local machine and then load it into TImageEnMView using LoadFromFileOnDemand. My question is: When can I safely delete the locally downloaded image files without affecting the use of the CopyToIEBitmap method?

Here is my code:

while not rs.eof do  
begin  
  PhotoStream := TBytesStream.Create;  
  vImageName := rs.fieldbyname('imagename').ToString;  
  try  
    if RequestStream('get', 'test03', vImageName, vMsg, PhotoStream) then  
    begin  
      PhotoStream.Position := 0;  
      PhotoStream.SaveToFile(vImageName);  
      ImageEnMView.LoadFromFileOnDemand(vImageName, True);  
      TFile.Delete(vImageName); // When to delete it? 
    end;  
  finally  
    PhotoStream.Free;  
  end;  
  rs.next;  
end;

xequte

38950 Posts

Posted - Apr 21 2025 :  02:41:34  Show Profile  Reply
Hi

If your StoreType is ietNormal then you can delete the file after it is loaded into TImageEnMView. The OnImageLoaded will fire after loading of each image:

https://www.imageen.com/help/TImageEnMView.OnImageLoaded.html

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

Flashcqxg

115 Posts

Posted - Apr 21 2025 :  02:52:49  Show Profile  Reply
Hi
Thank you.
I tested it, and the images that are displayed can be deleted after loading, but for the other images, you need to scroll to display them before they can be deleted.
Go to Top of Page

Flashcqxg

115 Posts

Posted - Apr 21 2025 :  02:54:49  Show Profile  Reply
That is to say, for the images that are not displayed in the ImageEnMView, I have to drag the vertical scroll bar before they can be deleted. Is there a way to delete them directly after loading?
Go to Top of Page

xequte

38950 Posts

Posted - Apr 21 2025 :  22:39:56  Show Profile  Reply
Hi

In OnImageLoaded, you should only delete the image of the relevant idx parameter. Each image only exists in TImageEnMView once OnImageLoaded as occurred for THAT image.

// After image has loaded, delete the file
procedure TForm1.ImageEnMView1ImageLoaded(Sender: TObject; Idx: Integer);
var
  fn: string;
begin
  fn := ImageEnMView1.ImageFilename[ Idx ];
  DeleteFile( fn );
end;

(Assuming you are not adding frames of a multi-frame format to TImageEnMView, which is a different story).


Nigel
Xequte Software
www.imageen.com
Go to Top of Page

Flashcqxg

115 Posts

Posted - Apr 21 2025 :  22:44:35  Show Profile  Reply
Is there any way to automatically load all the images into TImageEnMView without dragging the scroll bar?
Go to Top of Page

Flashcqxg

115 Posts

Posted - Apr 22 2025 :  20:22:27  Show Profile  Reply
Alternatively, is it possible to achieve Load From Stream On Demand?
Go to Top of Page

xequte

38950 Posts

Posted - Apr 23 2025 :  00:51:17  Show Profile  Reply
Hi

To force loading you can use:

http://www.imageen.com/help/TIECustomMView.EnsureImageLoaded.html


But the whole point of LoadFromFileOnDemand is only to load them as you scroll, otherwise you should just force loading with MIO.LoadFromFile() or AppendImage().



Nigel
Xequte Software
www.imageen.com
Go to Top of Page

Flashcqxg

115 Posts

Posted - Apr 23 2025 :  01:19:57  Show Profile  Reply
I see,thanks.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: