function TImageFileList.GetIndex: integer;
begin
result:=FIndex;
end;
--------------------------------------------------------------------------------
function TImageFileList.GetNextFileName: string;
begin
if Findex=FStrListFile.Count-1 then
Findex:=0
else
inc(Findex);
result:=FStrListFile.Strings[Findex];
end;
--------------------------------------------------------------------------------
function TImageFileList.GetPreFileName: string;
begin
if Findex=0 then
Findex:=FStrListFile.Count-1
else
dec(Findex);
result:=FStrListFile.Strings[Findex];
end;
--------------------------------------------------------------------------------
procedure TImageFileList.SetIndex(AIndex: integer);
begin
FIndex:=AIndex;
end;
3. 过程JpgToBmp及函数IsJpgFile的代码如下所示:
//转换jpg到bmp
procedure JpgToBmp(const JpgFileName:string;AJpg:TJpegImage;Abmp:Tbitmap);
begin
try
AJpg.LoadFromFile(JpgFileName);
Abmp.Assign(AJpg);
finally
end;
end;
//仅从扩展名上来判断是否是jpg格式的文件
function IsJpgFile(const FileName:string):boolean;
begin
result:=(LowerCase( ExtractFileExt(FileName))=''.jpg'') or (LowerCase( ExtractFileExt(FileName))=''.jpeg'');
end;
4. 我们在窗体的OnCreate和OnDestroy事件处理句柄里添加如下代码:
procedure TForm1.FormCreate(Sender: TObject);
begin
//设置图标间距,也即缩略图间距
ListView_SetIconSpacing(listview1.handle,90,120);
OriginalBmp:=Tbitmap.Create;
ThumbJpg:=TJpegImage.Create;
PreViewBmp:=Tbitmap.Create;
PreViewJpg:=TJpegImage.Create;
ThumbBmp:=TBitmap.Create;
//缩略图的边框为:80*80,显示图片大小为:64*64
ThumbBmp.Height:=80;
ThumbBmp.Width:=80;
ThumbBmp.PixelFormat:=pf24bit;
imagelist1.Height:=80;
imagelist1.Width:=80;
listview1.LargeImages:=imagelist1;
listview1.ViewStyle:=vsicon;
ImageFileList:=TImageFileList.Create;
ImageFileList.Clear;
ProgressBar1:=TProgressBar.Create(self);
ProgressBar1.Parent:=StatusBar1;
ProgressBar1.Visible:=false;
ProgressBar1.Width:=200;
ProgressBar1.Height:=StatusBar1.Height-4;
ProgressBar1.Left:=StatusBar1.Width-ProgressBar1.Width;
ProgressBar1.Top:=2;
IsRefreshImageFinished:=true;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
OriginalBmp.Free;
ThumbBmp.Free;
ImageFileList.Free;
ThumbJpg.Free;
PreViewBmp.Free;
PreViewJpg.Free;
ProgressBar1.Free;
end;
5. 在ShellTreeView1的OnChange事件里添加下面代码:
procedure TForm1.ShellTreeView1Change(Sender: TObject; Node: TTreeNode);
var
dir:string;
begin
//如果上次的RefreshImage过程还没有结束,就退