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
 Stop Loading Thumbnails
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

plumothy

United Kingdom
7 Posts

Posted - Nov 16 2012 :  06:54:57  Show Profile  Reply
I am just starting out with ImageEn.

I have a TImageEnMView loading thumbnails with the FillFromDirectory method.

How can I stop loading thumbnails before it finishes? (A user might want to do this if they accidentally select a folder with thousands of images and it is taking a long time to load them all.)

Steve Bailey,
ImageEn 4.1.4
Delphi XE3 Professional
Windows 7 Professional

cpstevenc

USA
125 Posts

Posted - Nov 16 2012 :  10:51:33  Show Profile  Reply
I have something similar going on myself. A user has a dropbox folder they use for images and some have hundreds of images. So takes forever to populate thumbnails for him sometimes.
Go to Top of Page

w2m

USA
1990 Posts

Posted - Nov 16 2012 :  11:46:11  Show Profile  Reply
If you look at the FillFromDirectory code you will see that there are no provisions to abort the 'Fill' in the current version. The current version only breaks when you set a limit on the number of files to be loaded.
if (Limit>-1) and (count=limit) then
  break;

So if you get a count on the number of images in the folder you can call FillFromDirectory with limits or allow the user to load all the files anyway.

function GetFileCount(AFolder, AWildCard: string): Integer;
//Return the AFolder file count
var
  iIntegerFound: Integer;
  iSearchRec: TSearchRec;
begin
  Screen.Cursor := crHourGlass;
  try
    Result := 0;
    if (AFolder <> '') and (AFolder[Length(AFolder)] <> '\') then
      AFolder := AFolder + '\';
    iIntegerFound := FindFirst(AFolder + AWildCard, faAnyFile, iSearchRec);
    while (iIntegerFound = 0) do
    begin
      if not (iSearchRec.Attr and faDirectory = faDirectory) then
        Inc(Result);
      iIntegerFound := FindNext(iSearchRec);
    end;
    FindClose(iSearchRec);
  finally
    Screen.Cursor := crDefault;
  end;
end;

procedure TForm1.FillFromDirectory1Click(Sender: TObject);
var
  iResult: integer;
  iFileCount: integer;
  iMax: integer;
  iMessage: string;
begin
  // Fill ImageEnMView with images from a folder
  if DirectoryExists(AFolder) then
  begin
    iFileCount := GetFileCount(AFolder, '*');
    iMax := StrToIntDef(Max1.Text, 5);
    if iFileCount > iMax then
    begin
      iMessage := 'The Folder Has ' + IntToStr(iFileCount) + ' Files.' + #10#13 + #10#13 +
        'Select "Yes" to load all files, select "No" to load ' + IntToStr(iMax) +
          ' files.  Select "Cancel" to abort.';
      iResult := MessageBox(0, PWideChar(iMessage),
        'Add All Images', MB_ICONQUESTION or MB_YESNOCANCEL);
      if iResult = idYes then
        iMax := -1
      else if iResult = idNo then
        iMax := StrToIntDef(Max1.Text, 5)
      else
        exit;
    end;
    ImageEnMView1.Clear;
    ImageEnView1.Clear;
    iResult := MessageBox(0, 'Add supported image types only?' + #10#13 + #10#13 +
      'If Yes then only known and supported file formats will be loaded, if No then all files will be loaded.  If Cancel then abort.',
      'Add Supported Images Only', MB_ICONQUESTION or MB_YESNOCANCEL);
    if iResult = idYes then
    begin
      Caption := 'ImageEnMView Thumbnail Spacing From A To Z With DragAndDrop- All Supported Images In '
        + AFolder;
      ImageEnMView1.FillFromDirectory(AFolder, iMax, False, '', True, '', False);
    end
    else if iResult = idNo then
    begin
      Caption := 'ImageEnMView Thumbnail Spacing From A To Z With DragAndDrop- All Supported Files In '
        + AFolder;
      ImageEnMView1.FillFromDirectory(AFolder, iMax, True);
    end
    else if iResult = idCancel then
    begin
      Caption := 'ImageEnMView Thumbnail Spacing From A To Z With DragAndDrop';
      exit;
    end;
    Screen.Cursor := crHourGlass;
    try
      ImageEnMView1.GridWidth := StrToIntDef(Columns1.Text, 3);
      ImageEnMView1.Width := ((ImageEnMView1.ThumbWidth + ImageEnMView1.HorizBorder) *
        ImageEnMView1.GridWidth) + ImageEnMView1.HorizBorder * 2;
      ImageEnMView1.Update;
      ImageEnMView1.SelectedImage := 0;
      AFilename := ImageEnMView1.ImageFileName[0];
      ImageEnView1.IO.LoadFromFile(AFilename);
      if Fit1.Checked then
        ImageEnView1.Fit;
      ImageEnMView1.GridWidth := StrToIntDef(Columns1.Text, 3);
      ImageEnMView1.Width := ((ImageEnMView1.ThumbWidth + ImageEnMView1.HorizBorder) *
        ImageEnMView1.GridWidth) + ImageEnMView1.HorizBorder * 5;
      ImageEnMView1.Update;
      ImageEnView1.Bitmap.Modified := False;
      StatusBar1.Panels[0].Text := ExtractFileDir(AFilename);
      StatusBar1.Panels[1].Text := ExtractFileName(AFilename);
    finally
      Screen.Cursor := crDefault;
    end;
  end
  else
    MessageBox(0, PChar('The folder ' + AFolder + ' does not exist.'), 'Warning', MB_ICONWARNING or
      MB_OK);
end;


William Miller
Email: w2m@frontiernet.net
EBook: http://www.imageen.com/ebook/
Apprehend: http://www.frontiernet.net/~w2m/index.html
Go to Top of Page

plumothy

United Kingdom
7 Posts

Posted - Nov 16 2012 :  13:43:39  Show Profile  Reply
OK - that's a shame.

Perhaps it's something the developers could consider for a future release.

Steve Bailey,
ImageEn 4.1.4
Delphi XE3 Professional
Windows 7 Professional
Go to Top of Page

fab

1310 Posts

Posted - Nov 18 2012 :  02:36:24  Show Profile  Reply
Because FillFromDirectory just create a list of images to load that will be loaded using multiple threads, you can cancel loading just calling TImageEnMView.Clear. Of course it will remove also already loaded images.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: