如何获得的位图transparancy,而不需要先画? [英] How to get bitmap transparancy without the need to paint first?

查看:123
本文介绍了如何获得的位图transparancy,而不需要先画?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个新创建的位图似乎有默认情况下(白色)的背景。至少,在像素属性证实的查询。但是,为什么是,背景颜色不作为透明色当透明设置为true?

A newly created bitmap seems to have a (white) background by default. At least, a query on the Pixels property confirms. But why is that background color not used as the transparent color when Transparent is set true?

考虑这个简单的测试code:

Consider this simple test code:

procedure TForm1.Button1Click(Sender: TObject);
var
  Bmp: TBitmap;
begin
  Bmp := TBitmap.Create;
  try
    Bmp.Width := 100;
    Bmp.Height := 100;
    Bmp.Transparent := True;
    Canvas.Draw(0, 0, Bmp);                              // A white block is drawn
    Bmp.Canvas.Brush.Color := Bmp.Canvas.Pixels[0, 99];  // = 'clWhite'
    Bmp.Canvas.FillRect(Rect(0, 0, 100, 100));
    Canvas.Draw(0, 100, Bmp);                            // "Nothing" is drawn
  finally
    Bmp.Free;
  end;
end;

由于某些原因,整个位面都必须涂,才可以显示为透明,这听起来有点古怪。

For some reason, the entire bitmap surface has to be painted before it can appear transparent, which sounds kind of odd.

以下变化试图消除调用 FillRect ,都具有相同的结果(无transparancy):

The following variations are tried to eliminate the call to FillRect, all with the same outcome (no transparancy):


  • 只有设置 Brush.Color

  • Brush.Handle:= CreateSolidBrush(clWhite)

  • 的PixelFormat:= pf32Bit

  • IgnorePalette:= TRUE

  • TransparantColor:= clWhite

  • TransparantMode:= tmFixed

  • Canvas.Pixels [0,99]:= clWhite 这让只有像素透明,

  • 修改:= TRUE

  • Only setting Brush.Color,
  • Brush.Handle := CreateSolidBrush(clWhite),
  • PixelFormat := pf32Bit,
  • IgnorePalette := True,
  • TransparantColor := clWhite,
  • TransparantMode := tmFixed,
  • Canvas.Pixels[0, 99] := clWhite which makes only thát pixel transparent,
  • Modified := True.

所以,愿望是只绘制新创建的位图的一部分,并获得剩余的表面透明。

So, the wish is to paint only a portion of a newly created bitmap and get the remaining surface transparent.

使用:德尔福7,赢7/64

Using: Delphi 7, Win 7/64.

推荐答案

只要设置 TransparentColor和 Canvas.Brush.Color设置位图尺寸了。

Just set TransparentColor and Canvas.Brush.Color before setting dimensions of the bitmap.

这篇关于如何获得的位图transparancy,而不需要先画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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