Optimization and correction of Delphi image skin replacement processing

Source: Internet
Author: User
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.

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.