小编Mar*_*cio的帖子

将32位Bitmap添加到ImageList

我正在尝试在运行时创建并绘制一个32位位图,然后将其添加到ImageList.位图具有透明度(alpha通道).我可以创建位图并在它的Canvas上绘制没有任何问题,并且它在任何其他画布上都具有透明度.

问题是当我将它添加到ImageList时,图像似乎丢失了使用位图的Canvas属性制作的图形.

以下是我启动Bitmap的方法:

Bitmap := TBitmap.Create;
Bitmap.PixelFormat := pf32bit;
Bitmap.Transparent := True;
Bitmap.AlphaFormat := afDefined;
SetBkMode(Bitmap.Canvas.Handle, TRANSPARENT);
Bitmap.SetSize(100, 42);

// now I can draw, let's say, an icon from an imagelist
ImageList.Draw(Bitmap.Canvas, 5, 5, 0, dsTransparent, itImage);

// and some other stuff
Bitmap.Canvas.RoundRect(0, 0, 99, 41, 5, 5);
Bitmap.Canvas.TextOut(50, 5, 'Test string');
Run Code Online (Sandbox Code Playgroud)

如果我将此Bitmap绘制到任何控件画布,它会使用图像列表中的图像,圆角矩形和文本,使用透明背景(任何未绘制的任何内容都是透明的;将保留已存在的背景)进行正常绘制.这意味着Form1.Canvas.Draw(0, 0, Bitmap);将在Form1上绘制位图,如果那里有任何其他图像,它将保留为背景.

但是,如果我将此位图添加到图像列表,则会出现奇怪的问题.ImageList将ColorDepth设置为cd32bit,然后调用:

BitmapImageList.Width := Bitmap.Width;
BitmapImageList.Hieght := Bitmap.Height;
BitmapImageList.Add(Bitmap, nil);
Run Code Online (Sandbox Code Playgroud)

现在,如果我尝试从图像列表中绘制该图像:

BitmapImageList.Draw(Form1.Canvas, 0, 0, 0);
Run Code Online (Sandbox Code Playgroud)

将显示的唯一内容是从ImageList在Bitmap中绘制的图像,圆角矩形和在Canvas中绘制的文本消失.

我错过了什么?

delphi transparency bitmap imagelist

6
推荐指数
1
解决办法
3476
查看次数

标签 统计

bitmap ×1

delphi ×1

imagelist ×1

transparency ×1