TImageList
False
允许您使用作为最后一个参数将其中一个图像绘制到处于禁用状态的位图。
ImageList.Draw(DestBitmap.Canvas, 0, 0, ImageIndex, False);
我想这样做,也想灰度目标位图。
我有以下代码:
procedure ConvertBitmapToGrayscale(const Bitmap: TBitmap);
type
PPixelRec = ^TPixelRec;
TPixelRec = packed record
B: Byte;
G: Byte;
R: Byte;
Reserved: Byte;
end;
var
X: Integer;
Y: Integer;
P: PPixelRec;
Gray: Byte;
begin
Assert(Bitmap.PixelFormat = pf32Bit);
for Y := 0 to (Bitmap.Height - 1) do
begin
P := Bitmap.ScanLine[Y];
for X := 0 to (Bitmap.Width - 1) do
begin
Gray := Round(0.30 * P.R + 0.59 * P.G + 0.11 * P.B);
P.R := Gray;
P.G := Gray;
P.B := Gray;
Inc(P);
end;
end;
end;
procedure DrawIconShadowPng(ACanvas: TCanvas; const ARect: TRect; ImageList:
TCustomImageList; ImageIndex: Integer);
var
ImageWidth, ImageHeight: Integer;
GrayBitMap : TBitmap;
begin
ImageWidth := ARect.Right - ARect.Left;
ImageHeight := ARect.Bottom - ARect.Top;
with ImageList do
begin
if Width < ImageWidth then ImageWidth := Width;
if Height < ImageHeight then ImageHeight := Height;
end;
GrayBitMap := TBitmap.Create;
try
GrayBitmap.PixelFormat := pf32bit;
GrayBitMap.SetSize(ImageWidth, ImageHeight);
ImageList.Draw(GrayBitMap.Canvas, 0, 0, ImageIndex, False);
ConvertBitmapToGrayscale(GrayBitMap);
BitBlt(ACanvas.Handle, ARect.Left, ARect.Top, ImageWidth, ImageHeight,
GrayBitMap.Canvas.Handle, 0, 0, SRCCOPY);
finally
GrayBitMap.Free;
end;
end;
这样做的问题是生成的图像具有白色背景。
如何让背景透明?
我正在使用 TPngImageList,因为它比常规 TImageList 更好地处理 Png 图像。(在 XE4 中)