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
 TImageEnMView, change internal Thumbnail size
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

spockhh

Germany
2 Posts

Posted - Apr 23 2019 :  10:51:31  Show Profile  Reply
Hi,
in the OnImageLoaded event I save the generated thumbnails for later use on disk in a special subdir ..\_thumbs.
The size of thumbnails is always 750x500 or 500x750 pixel (images have 2:3 ratio).
I can't find the correct option to change this size, I want them smaller.
Sorry for my bad english...
Thanks for your help
Arnd Nolte
motionphotos


function ThumbFilename(AFilename: string): string;
begin
  Result := TPath.Combine(ExtractFilePath(AFilename), '_thumbs');
  Result := TPath.Combine(Result, ExtractFilename(AFilename));
  // Result := ChangeFileExt(Result, '.bmp');
end;

procedure TFormMain.IEMView1ImageLoaded(Sender: TObject; idx: Integer);
var
  IEIO: TImageEnIO;
  sThumbFilename: string;
begin
  // sl.Add('OnImageLoaded ' + IEMView1.ImageFileName[idx]);
  sThumbFilename := ThumbFilename(IEMView1.ImageFileName[idx]);
  if not System.SysUtils.FileExists(sThumbFilename) then
  begin
    IEIO := TImageEnIO.CreateFromBitmap(IEMView1.GetTIEBitmap(idx));
    try
      IEIO.Params.JPEG_Quality := 90;
      ForceDirectories(ExtractFilePath(sThumbFilename));
      IEIO.SaveToFile(sThumbFilename);
    finally
      IEIO.Free;
    end;
  end;
end;

procedure TFormMain.IEMView1ImageOut(Sender: TObject; idx: Integer; OutBitmap: TIEBitmap);
begin
  // sl.Add('OnImageOut ' + IEMView1.ImageFileName[idx]);
  OutBitmap.IECanvas.Font.Size := 24;
  OutBitmap.IECanvas.DrawText(ExtractFilename(IEMView1.ImageFileName[idx]),
    Rect(0, 0, OutBitmap.Width, OutBitmap.Height));
end;

procedure TFormMain.FormCreate(Sender: TObject);
begin
  with IEMView1 do
  begin
    Align := alClient;
    Parent := self;
    Background := clWindow;
    FlatScrollBars := True;
    TextMargin := 4;
    GridWidth := -1;
    SelectionWidth := 1;
    SelectionColor := $CEA27D;
    Style := iemsFlat;
    AutoAdjustStyle := False;

    ThumbWidth := 150;
    ThumbHeight := 150;
    StoreType := ietFastThumb;
    ThumbnailsBorderWidth := 0;
    // ThumbnailsBorderWidth := 1;
    ThumbnailsBackground := clWindow;
    ThumbnailsBackgroundSelected := $FCEADA;
    // ThumbnailResampleFilter := rfFastLinear;
    ThumbnailResampleFilter := rfBiCubic;
    ThumbnailDisplayFilter := rfFastLinear;
    ThumbnailsBorderCurved := False;
    HorizBorder := 2;
    VertBorder := 2;

    EnableMultiSelect := True;
    MultiSelectionOptions := [iemoRegion, iemoOptimizeForDragging, iemoSelectOnRightClick];

    DefaultTopText := iedtNone;
    DefaultInfoText := iedtNone;
    DefaultBottomText := iedtFilename;
    BottomTextFont.Color := clGray;
    BottomTextFont.Name := 'Segoe UI';
    BottomTextFont.Size := 7;
    SelectedFontColor := clNone;

    MouseWheelParams.Action := iemwVScroll;
    MouseWheelParamsAlt.Action := iemwZoom;

    EnableAdjustOrientation := True;
    EnableImageCaching := True;

    //
    OnImageOut := IEMView1ImageOut;
    OnImageLoaded := IEMView1ImageLoaded;
    OnImageFilename := IEMView1ImageFilename;

    ImageCacheSize := 512;
    LookAhead := 80;
  end;
end;

xequte

38717 Posts

Posted - Apr 23 2019 :  20:16:30  Show Profile  Reply
Hi

If your goal is just to create thumbnails from a folder images, you should not use a TImageEnMView for this.

You should iterate through the images in the folder (e.g. using Windows.FindFirstFile/Windows.FindNextFile) and then load/resample/save using a TIEBitmap or the helper function IECreateThumbnailFromFile:

https://www.imageen.com/help/IECreateThumbnailFromFile.html



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

spockhh

Germany
2 Posts

Posted - Apr 24 2019 :  04:45:39  Show Profile  Reply
Hi,
the advantage of using the TImageEnMView is:
- the user can start working immediatliy after selection of a directory
- the creating of thumbnails works fine in multiple threads

I modified the mview.pas, I implemented an OnGetThumbFilename event before loading an image. If a thumbnail file (see above) was created, it will be used instead of the original file. Loadinging in network is faster and I can use the created thumbnail file in other parts of my software.

This is the reason I want to know, how to change the size... If a cannot change it, it would be OK, if the size remains 750x750 pixel.

Arnd
Go to Top of Page

xequte

38717 Posts

Posted - Apr 28 2019 :  20:18:08  Show Profile  Reply
Hi

Thanks for the explanation. I have added an OnGetLoadFilename event.

Here is an example of how it might be used:

procedure TMyForm.ImageEnMViewOnGetLoadFilename(Sender: TObject; Index: integer; var Filename: string);
var
  cacheFilename: string;
begin
  // Use our own cache as a source for thumbnails
  cacheFilename := LookupCacheTable( Filename );
  if cacheFilename = '' then
  begin
    cacheFilename := GenerateCacheFile( Filename );
    AddToCacheTable( Filename, cacheFilename );
  end;

  Filename := cacheFilename;
end;


In your case, you are caching the thumbnail that the TImageEnView has created. The size of these thumbnails cannot be guaranteed as it is based on several factors, such as:
- StoreType
- ThumbWidth/ThumbHeight
- EnableLoadEXIFThumbnails
- EnableLoadExplorerThumbnails
- etc.


Nigel
Xequte Software
www.imageen.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: