Re-learning gdi+[100]: Tgpimage (20)

Source: Internet
Author: User
Tags integer

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.