//添加顏色變換uses GDIPAPI, GDIPOBJ;
procedure TForm1.FormPaint(Sender: TObject);
var
g: TGPGraphics;
img: TGPImage;
imgAtt: TGPImageAttributes;
const
ColorMatrix: TColorMatrix = (
(1.0, 0.0, 0.0, 0.0, 0.0),
(0.0, 1.0, 0.0, 0.0, 0.0),
(0.0, 0.0, 1.0, 0.0, 0.0),
(0.0, 0.0, 0.0, 1.0, 0.0),
(1.0, 0.0, 0.0, 0.0, 1.0));
begin
g := TGPGraphics.Create(Canvas.Handle);
img := TGPImage.Create('c:\temp\test.png'); {測試文件要存在}
imgAtt := TGPImageAttributes.Create;
imgAtt.SetColorMatrix(colorMatrix, ColorMatrixFlagsDefault, ColorAdjustTypeDefault);
g.DrawImage(
img,
MakeRect(0,0,img.GetWidth,img.GetHeight),
0,
0,
img.GetWidth,
img.GetHeight,
UnitPixel,
imgAtt);
imgAtt.Free;
img.Free;
g.Free;
end;
//效果圖: