我很惊讶这TImage32
没有透明度。你真的确定是这样吗?
无论如何,如果是这样,我会将透明度支持TImage
与重新采样能力相结合,TBitmap32
以这种方式构建解决方案。将原始图像保留在TBitmap32
实例中。每当您需要将其加载到TImage
组件中时,例如在重新调整大小时,使用TBitmap32
执行内存中重新调整大小并加载该重新调整大小的图像。
事实上,如果您已经在自己绘制表单的背景,为什么不自己绘制图像并简单地取消图像控件呢?
更新 1: Websearch 揭示了一种使 TImage32 透明的简单方法:http ://graphics32.org/news/newsgroups.php?art_group=graphics32.general&article_id=9505
更新 2:上面的链接现在已经失效,新闻组只能通过 NNTP 访问。我不能 100% 确定,但我认为链接的帖子是 Michael Haralabos 的,并且包含以下文件:
unit GR32_ImageEx;
// Transparent TImage32 by Michael Haralabos
interface
uses
Windows, Messages, Classes, GR32_Image, GR32;
type
TImage32Ex = class(TImage32)
private
FTransparent: Boolean;
procedure SetTransparent(const Value: Boolean);
public
procedure ExecClearBackgnd(Dest: TBitmap32; StageNum: Integer); override;
published
property Enabled;
property Transparent: Boolean read FTransparent write SetTransparent;
end;
procedure Register;
implementation
procedure TImage32Ex.ExecClearBackgnd(Dest: TBitmap32; StageNum: Integer);
var
P: TPoint;
SaveIndex: Integer;
begin
if FTransparent and Assigned(Parent) and
not (Assigned(Bitmap) and (BitmapAlign = baTile)) then
begin
SaveIndex := SaveDC(Dest.Handle);
GetViewportOrgEx(Dest.Handle, P);
SetViewportOrgEx(Dest.Handle, P.X - Left, P.Y - Top, nil);
IntersectClipRect(Dest.Handle, 0, 0, Parent.ClientWidth, Parent.ClientHeight);
Parent.Perform(WM_ERASEBKGND, Dest.Handle, 0);
Parent.Perform(WM_PAINT, Dest.Handle, 0);
RestoreDC(Dest.Handle, SaveIndex);
end
else
inherited;
end;
procedure TImage32Ex.SetTransparent(const Value: Boolean);
begin
if FTransparent <> Value then
begin
FTransparent := Value;
Invalidate;
end;
end;
procedure Register;
begin
RegisterComponents('Graphics32', [TImage32Ex]);
end;
end.
这里的另一个主题表明这可能是现在死链接所指的内容:Delphi TImage32 - 如果没有加载图片,如何使组件不可见?