This example effect chart:
Code files:Unit Unit1;
Interface
Uses
Windows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms,
Dialogs, Stdctrls, Tecanvas;
Type
TForm1 = Class (Tform)
Buttoncolor1:tbuttoncolor;
Button1:tbutton;
Procedure Formcreate (Sender:tobject);
Procedure Formdestroy (Sender:tobject);
Procedure Formpaint (Sender:tobject);
Procedure Buttoncolor1click (Sender:tobject);
Procedure Formmouseup (Sender:tobject; Button:tmousebutton;
Shift:tshiftstate; X, Y:integer);
Procedure Button1Click (Sender:tobject);
End
Var
Form1:tform1;
Implementation
{$R *.DFM}
Uses Gdipobj, GDIPAPI;
Var
Img:tgpimage;
Imageattributes:tgpimageattributes;
colormap:array[0..0] of Tcolormap; {Each element contains both new and old colors}
Procedure Tform1.formcreate (Sender:tobject);
Begin
IMG: = tgpimage.create (' c:\temp\test.png ');
ClientWidth: = img. getwidth;
ClientHeight: = img. GetHeight;
ImageAttributes: = tgpimageattributes.create;
Colormap[0].oldcolor: = Aclblack;
Colormap[0].newcolor: = Aclblack;
Buttoncolor1.caption: = ' replace ';
Button1.caption: = ' restitution ';
End
Procedure Tform1.formdestroy (Sender:tobject);
Begin
Img. Free;
Imageattributes.free;
End
Procedure Tform1.formmouseup (Sender:tobject; Button:tmousebutton;
Shift:tshiftstate; X, Y:integer);
Var
Color:tcolor;
Begin
Color: = GetPixel (Canvas.handle, X, Y);
Colormap[0].oldcolor: = Colorreftoargb (color);
Buttoncolor1.symbolcolor: = color;
Buttoncolor1.refresh;
End
Procedure Tform1.formpaint (Sender:tobject);
Var
G:tgpgraphics;
Begin
G: = Tgpgraphics.create (Canvas.handle);
G.drawimage (IMG,
Makerect (0, 0, img.) GetWidth, IMG. GetHeight),
0, 0,
Img. GetWidth, IMG. GetHeight,
Unitpixel,
ImageAttributes
);
G.free;
End
Procedure Tform1.button1click (Sender:tobject);
Begin
Buttoncolor1.symbolcolor: = Argbtocolorref (colormap[0). Oldcolor);
buttoncolor1.enabled: = True;
Buttoncolor1.update;
imageattributes.clearremaptable; {clearremaptable}
Repaint;
End
Procedure Tform1.buttoncolor1click (Sender:tobject);
Begin
Colormap[0].newcolor: = Colorreftoargb (Buttoncolor1.symbolcolor);
Imageattributes.setremaptable (Length (ColorMap), @ColorMap); {setremaptable}
Repaint;
buttoncolor1.enabled: = False;
End
End.