TBitmap德尔福2009年绘制透明图像 [英] TBitmap drawing transparent image in Delphi 2009

查看:263
本文介绍了TBitmap德尔福2009年绘制透明图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题的TBitmap对象上画一个半透明的PNG图像。

Problem in drawing a semi transparent PNG image on TBitmap object.

如果该TBitmap的,HandleType设为bmDDB,则帆布绘制透明。
但问题是它不能在各种机器工作。(为前:在苹果电脑上的Windows)

If the TBitmap's ,HandleType is set to bmDDB, then the canvas is drawn transparent. But the problem is it doesn't work on all kinds of machines (for ex: Windows on apple computers).

当一个TBitmap的HandleType属性设置为bmDIB,画布背景绘制白色。

When a TBitmap's HandleType property is set to bmDIB, canvas background is drawn white.

bmp.HandleType := bmDIB;

我试着刷样式设置为bsCle​​ar。但是,在绘制黑色的透明像素。

I tried setting Brush style to bsClear. But it draws the transparent pixels in black color.

我如何绘制图像preserving其透明度和光滑的弧形边缘。

How can I draw an image preserving its transparency and smooth curved edges.

谢谢
帕文。

推荐答案

这当然是可能的油漆与透明背景的画布一个 bmDIB 位图:

It is certainly possible to paint a bmDIB bitmap with transparent background to a canvas:

procedure TForm1.FormPaint(Sender: TObject);
var
  Bmp: TBitmap;
begin
  Bmp := TBitmap.Create;
  try
    Bmp.PixelFormat := pf32bit;
    Bmp.HandleType := bmDIB;
    Bmp.Width := 700;
    Bmp.Height := 400;
    Bmp.Transparent := TRUE;
    Bmp.TransparentColor := clMaroon;

    with Bmp.Canvas do begin
      Brush.Color := clMaroon;
      FillRect(Rect(0, 0, Bmp.Width, Bmp.Height));

      Brush.Color := clBlue;
      FillRect(Rect(42, 42, 200, 300));
    end;

    Canvas.Draw(12, 12, Bmp);
  finally
    Bmp.Free;
  end;
end;

请注意,整个位图先用颜色设置为 TransparentColor 填写。

Note that the whole bitmap is filled first with the colour set as TransparentColor.

但对于更多的控制和速度,你应该寻找到一个解决方案,而不是依赖于GDI(涉及图形卡和驱动程序的功能),类似的 Graphics32

But for more control and speed you should look into a solution that is not as dependent on the GDI (which involves graphics card and driver capabilities), something like Graphics32.

这篇关于TBitmap德尔福2009年绘制透明图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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