// experimental code
procedure TFormMain.MyThumbnailProvider(const Path: Unicodestring; Width,
Height: Integer; out Bitmap: TBitmap);
var
AExtension: string;
ARect: TRect;
begin
AExtension := LowerCase(ExtractFileExt(Path));
if AExtension = '.wmf' then
begin
ARect.Left := 0;
ARect.Top := 0;
ARect.Right := Width;
ARect.Bottom := Height;
Image1.Picture.LoadFromFile(Path); // added at design time to form
Bitmap := TBitmap.Create;
Bitmap.Width := Width;
Bitmap.Height := Height;
Bitmap.Canvas.StretchDraw(ARect, Image1.Picture.Graphic);
end;
end;
编辑这段代码线程安全
procedure TFormMain.MyThumbnailProvider(const Path: Unicodestring; Width, Height: Integer; out Bitmap: TBitmap);
var
ARect: TRect;
APicture: TPicture;
AExtension: string;
begin
// experimental code
if FileExists(Path) then
begin
AExtension := LowerCase(ExtractFileExt(Path));
if AExtension = '.wmf' then
begin
ARect.Left := 0;
ARect.Top := 0;
ARect.Right := Width;
ARect.Bottom := Height;
APicture := TPicture.Create;
try
APicture.LoadFromFile(Path);
Bitmap := TBitmap.Create;
Bitmap.SetSize(Width, Height);
Bitmap.IgnorePalette := True;
Bitmap.PixelFormat := pf24bit;
Bitmap.Transparent := False;
Bitmap.Canvas.Lock; **// New**
try
Bitmap.Canvas.StretchDraw(ARect, APicture.Graphic);
finally
Bitmap.Canvas.Unlock; **// New!**
end;
finally
APicture.Free;
end;
end;
end;
end;
这似乎彻底解决这一问题图纸!显然,在使用Draw或StretchDraw时,必须锁定和解锁画布,因为在线程中,由于graphics.pas中的GDI对象缓存机制,其Bitmap.canvas的DC有时会被清除。
见http://qc.embarcadero.com/wc/qcmain.aspx?d=55871
您在询问线程安全性,但在您的问题中看不到并发线程。你为什么要麻烦线程安全? – kludg 2011-04-26 14:39:10
您是否听说过Jim Kueneman的[VirtualShellTools library](http://mustangpeak.net/)?它在浏览器方式显示文件方面做得非常好,甚至可以处理缩略图视图。 Rob Rob。 – 2011-04-26 16:13:09
Rob。是的,我使用了Jim Kueneman的VirtualShellTools库多年。直到德尔福2009或2010年,它做得非常好。从那时起,我无法安装它,据我所知它还没有在一段时间内更新。即使Jim的用户群在一年内几乎没有任何活动。我认为Jim现在忙于其他事情...... Plasmatech似乎也停止了shell开发,只留下了JamShellBrower作为唯一可行的vcl shell ...这是非常好的,具有良好的支持以及最近的更新。 – Bill 2011-04-26 18:45:55