專注演示 TColorMatrix[3,3] 單一元素控制整體圖像透明度的最簡模型。
var ColorMatrix: TColorMatrix = ( ... ); { 單位矩陣 }
procedure TForm1.FormPaint(Sender: TObject);
var g: TGPGraphics; img: TGPImage; ImageAttributes: TGPImageAttributes;
begin
g := TGPGraphics.Create(Canvas.Handle);
img := TGPImage.Create('c:\temp\test.png');
ImageAttributes := TGPImageAttributes.Create;
{ 關鍵:[3,3] 控制 Alpha 通道縮放 }
ColorMatrix[3,3] := TrackBar1.Position / 100; { 0.0~1.0 }
ImageAttributes.SetColorMatrix(ColorMatrix);
g.DrawImage(img, MakeRect(0, 0, img.GetWidth, img.GetHeight), 0, 0, img.GetWidth, img.GetHeight, UnitPixel, ImageAttributes);
ImageAttributes.Free; img.Free; g.Free;
end;

ColorMatrix[3,3] 對應 Alpha 通道縮放因子TGPImageAttributes 套用至繪圖管線這是 ColorMatrix 最簡單、最實用的單參數應用,理解它為掌握完整 RGBA 矩陣操作打下基礎。