I have seen an article about skin replacement for PNG images, but there are some problems in color processing, which are specially optimized and corrected. This is intended to reply to the problem of group friends, so BMP images are used, PNG images are processed in the same way. The Code is as follows:
Unit unit1;
Interface
Uses
Windows, messages, sysutils, variants, classes, graphics, controls, forms,
Dialogs, stdctrls, extctrls;
Type
Tform1 = Class (tform)
Colorbox1: tcolorbox;
Procedure btn1click (Sender: tobject );
Procedure colorbox1select (Sender: tobject );
Procedure formpaint (Sender: tobject );
Private
{Private Declarations}
Public
{Public declarations}
End;
VaR
Form1: tform1;
Implementation
{$ R *. DFM}
Procedure tform1.btn1click (Sender: tobject );
VaR
I, J: integer;
Row: prgbtriple;
RGB: longint;
Rgb_r, rgb_g, rgb_ B: byte;
Gray: byte;
BMP: tbitmap;
Begin
RGB: = colortorgb (colorbox1.selected );
Rgb_r: = getrvalue (RGB );
Rgb_g: = getgvalue (RGB );
Rgb_ B: = getbvalue (RGB );
BMP: = tbitmap. Create;
Try
BMP. loadfromfile ('e:/Documents and Settings/siow/desktop/main.bmp ');
For I: = 0 to BMP. Height-1 do
Begin
Row: = BMP. scanline [I];
For J: = 0 to BMP. Width-1 do
Begin
// Grayscale
Gray: = trunc (row ^. rgbtred * 306 + row ^. rgbtgreen * 601 + row ^. rgbtblue * 117 + 512) SHR 10 );
Row ^. rgbtred: = round (255-(255-gray) * (255-rgb_r)/255 );
Row ^. rgbtgreen: = round (255-(255-gray) * (255-rgb_g)/255 );
Row ^. rgbtblue: = round (255-(255-gray) * (255-rgb_ B)/255 );
INC (ROW );
End;
End;
Self. Canvas. stretchdraw (BMP. Canvas. cliprect, BMP );
Finally
BMP. Free;
End;
End;
Procedure tform1.colorbox1select (Sender: tobject );
Begin
Btn1click (NiL );
End;
Procedure tform1.formpaint (Sender: tobject );
Begin
Btn1click (NiL );
End;
End.