Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4087232
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:49:45+00:00 2026-05-20T18:49:45+00:00

In DelphiXE, I’m using a tFileOpenDialog to select a folder and then listing all

  • 0

In DelphiXE, I’m using a tFileOpenDialog to select a folder and then listing all the *.jpg files in that folder in a tListBox. I’m allowing the list items to be dragged and dropped within the list for custom sorting so that I can display them in order later.

I’d like to be able to draw a thumbnail of the image beside the filename so that the display is similar to Windows Explorer when looking at files in List view where you have the associated icon just left of the file name on the same row.

I’ve found a couple of old examples that lead me to believe this is possible using tListBox.onDrawItem, but I’ve been unable to get one to work.

What is the best approach to take to accomplish this goal using a tListBox, or by some other means?

Thanks for your help.


Update: I’ve been working to use tListView instead, as suggested.

I’ve attempted to convert the examples from Ken and Andreas to use actual images instead of dynamically created sample bitmaps. I was able to get the basics working, but without resizing, I get only the top left of the image 64*64. I’m only working with JPGs at this point. imagecount is just the count of my list of filenames in my listbox, I haven’t moved the initial list creation into the listview at this point.

That is done with this code:

procedure TfrmMain.CreateThumbnails;
var
  i: Integer;
  FJpeg: TJpegImage;
  R: TRect;
begin
  for i := 0 to imageCount - 1 do
  begin
    FJpeg := TJpegImage.Create;
    thumbs[i] := TBitmap.Create;
    FJpeg.LoadFromFile(Concat(imgFolderlabel.caption,
      photoList.Items.Strings[i]));
    thumbs[i].Assign(FJpeg);
    thumbs[i].SetSize(64, 64); 
  end;
  imgListView.LargeImages := ImageList1;
  FJpeg.Free;
end;

In order to also resize and stretch the image properly within the thumbnail, I’m trying to implement some code from here: http://delphi.about.com/od/graphics/a/resize_image.htm

The new code looks like:


procedure TfrmMain.CreateThumbnails;
var
  i: Integer;
  FJpeg: TJpegImage;
  R: TRect;
begin
  for i := 0 to imageCount - 1 do
  begin
      FJpeg := TJpegImage.Create;
      thumbs[i] := TBitmap.Create;
      FJpeg.LoadFromFile(Concat(imgFolderlabel.caption,
        photoList.Items.Strings[i]));
      thumbs[i].Assign(FJpeg);
//resize code R.Left := 0; R.Top := 0; // proportional resize if thumbs[i].Width > thumbs[i].Height then begin R.Right := 64; R.Bottom := (64 * thumbs[i].Height) div thumbs[i].Width; end else begin R.Bottom := 64; R.Right := (64 * thumbs[i].Width) div thumbs[i].Height; end; thumbs[i].Canvas.StretchDraw(R, thumbs[i]); // resize image //thumbs[i].Width := R.Right; //thumbs[i].Height := R.Bottom;
thumbs[i].SetSize(64, 64); //all images must be same size for listview
end; imgListView.LargeImages := ImageList1; FJpeg.Free; end;

This gives me a collage of image thumbnails with their filenames and works good.

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T18:49:46+00:00Added an answer on May 20, 2026 at 6:49 pm

    Not an answer, but an alternative (using Andreas’ code for creating the image array as a starting point). Drop a TListView and a TImageList on a new form, cut all the code from the editor from the interface to just above the final end. with this:

    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, ImgList, ComCtrls;
    
    type
      TForm1 = class(TForm)
        ImageList1: TImageList;
        ListView1: TListView;
        procedure FormShow(Sender: TObject);
      private
        { Private declarations }
        procedure CreateListItems;
      public
        { Public declarations }
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    const
      N = 50;
      THUMB_WIDTH = 32;
      THUMB_HEIGHT = 32;
      THUMB_PADDING = 4;
    
    var
      thumbs: array[0..N-1] of TBitmap;
    
    procedure CreateThumbnails;
    var
      i: Integer;
    begin
      for i := 0 to N - 1 do
      begin
        thumbs[i] := TBitmap.Create;
        thumbs[i].SetSize(THUMB_WIDTH, THUMB_HEIGHT);
        thumbs[i].Canvas.Brush.Color := RGB(Random(255), Random(255), Random(255));
        thumbs[i].Canvas.FillRect(Rect(0, 0, THUMB_WIDTH, THUMB_HEIGHT));
      end;
    end;
    
    
    procedure TForm1.CreateListItems;
    var
      i: Integer;
    begin
      for i := 0 to N - 1 do
      begin
        with ListView1.Items.Add do
        begin
          Caption := 'Item ' + IntToStr(i);
          ImageIndex := i;
        end;
      end;
    end;
    
    procedure TForm1.FormShow(Sender: TObject);
    var
      i: Integer;
    begin
      CreateThumbnails;
      for i := 0 to N - 1 do
        ImageList1.Add(thumbs[i], nil);
      ListView1.LargeImages := ImageList1;
      CreateListItems;
    end;
    

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're using Delphi2005 with Delphi2007 patches, also experimenting with DelphiXE SOAP libraries. But I've
I'm using delphi XE. I'm developing a component that is come from TPanel. TApGUITab=class(Tpanel)
I am using DelphiIXE. I learned that GlobalMemoryStatus may return wrong results on 64
Using DelphiXE, I'm trying to show the length of a wav file on a
I am using Delphi 7 but I have trialed the Delphi 2005 - 2010
In Delphi XE, I'm trying to use GetForegroundWindow to detect the window that was
I am using Delphi 2009. On a huge project 300+ units, 5 third party
I'm using Delphi XE and I would like to make a button which shows
I'm using Delphi XE and would like to add recent items in the Windows
I am interested to re-evaluate Delphi 2010. The main issue seems to be the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.