在Delphi中使用重采样进行透明图像控制 [英] Transparent image control with resampling in Delphi

查看:102
本文介绍了在Delphi中使用重采样进行透明图像控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有背景图像的窗体(在Form1.Repaint中的窗体上绘制)。

I have a form with a background image (painted on the form in Form1.Repaint).

我要寻找的内容:

(我需要将其透明,因为窗体背景图像应该是可见的)

(I need it to be transparent because the forms background image should be visible through)

我尝试过的操作:


  • 标准TImage:这是透明的,但是

Graphics32 / Image32:美丽的重采样,但是不透明。

Graphics32 / Image32: Resamples beautifully, but it's not transparent.

我已经在Google上搜索了几个小时,以获取修复程序或解决方法,但没有太多解决方案。这与加载到Image32中的图像是透明的无关,但是控件的背景颜色仍然是白色(白色= Image32控件的颜色属性,将其设置为clNone不起作用)。 这显然是按设计的

I have googled for several hours now for fixes or work-arounds, but without much of a solution. This has nothing to do with the image loaded into Image32 being transparent, but instead the background color of the control still being white (white = the color-property of the Image32 control, and setting it to clNone does not work). This is apparently as designed

GR32ex (GR32扩展组件包),据说它添加了透明属性,但是多年没有更新,因此无法安装。它在Delphi 2010和Graphics32 v。1.9上引发了数百万个错误。

GR32ex (The GR32 Extension Components Pack), which supposedly adds a Transparent-property, however it has not been updated in many years, and I can not install it. It throws a gazillion errors on Delphi 2010 and Graphics32 v. 1.9.

有人能想到解决方案或解决方法吗?我想要的只是一个具有透明度和重新采样的控件。

Can anybody think of a solution or workaround? All I want is a control with transparency and resampling.

谢谢!

推荐答案

I对于 TImage32 没有透明性感到很惊讶。

I'm surprised that TImage32 doesn't do transparency. Are you really sure that is the case?

无论如何,如果是这样,我将结合 TImage 具有 TBitmap32 的重采样功能来构建这种解决方案。将原始图像保存在 TBitmap32 实例中。每当您需要将其加载到 TImage 组件中时(例如,重新调整大小时),请使用 TBitmap32 进行输入-memory重新调整大小并加载该重新调整大小的图像。

Anyway, if that is so, I would combine the transparency support of TImage with the re-sampling ability of TBitmap32 to build a solution that way. Keep the original image in a TBitmap32 instance. Whenever you need to load it into the TImage component, for example when re-sizing, use TBitmap32 to perform an in-memory re-size and load that re-sized image.

实际上,如果您已经在自己绘制窗体的背景,为什么不自己绘制图像并简单地做

In fact, if you are already painting the form's background yourself, why not paint the image yourself and simply do away with the image control?

更新1::Websearch揭示了一种使TImage32透明的简单方法: http://graphics32.org/news/newsgroups.php?art_group=graphics32.general&article_id=9505

Update 1: Websearch reveals a simple way to make TImage32 transparent: http://graphics32.org/news/newsgroups.php?art_group=graphics32.general&article_id=9505

更新2:上面的链接现在不可用了,新闻组只能通过NNTP访问。我不能100%确定,但我认为链接的帖子由Michael Haralabos撰写,并包含以下文件:

Update 2: The link above is now dead, and the newsgroups can only be accessed via NNTP. I can't be 100% certain, but I think that the linked post was by Michael Haralabos and contained the following file:

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-如果未加载图片,如何使组件不可见?

Another topic here suggests that this may be what the now dead link referred to: Delphi TImage32 - how to make the component invisible if no picture is loaded?

这篇关于在Delphi中使用重采样进行透明图像控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆