Delphi-based color conversion and pixel access

Source: Internet
Author: User

To simulate functions such as color searching and image searching, we must first familiarize ourselves with the relevant knowledge.

Our goal is to find the color and the image, so we only need to consider the 24 B color (pf24bit ).

The tcolor value is stored in hexadecimal format. The low Three Represent the saturation of red, green, and blue colors.

VaR

C: tcolor

R, G, B: byte;

Tcolor to RGB Value

R: = getrvalue (C );

G: = getgvalue (C );

B: = getbvalue (C );

Or

R: = C and $ ff;

G: = (C and $ ff00) SHR 8;

B: = (C and $ ff0000) SHR 16;

Convert RGB to tcolor

C: = strtoint (inttohex (B, 2) + inttohex (G, 2) + inttohex (R, 2 ));

Or

C: = RGB (R, G, B );

Quick access to BMP pixels. scanline is generally used.

Type // supplementary definition for ease of use

Prgbtriparray = ^ trgbtriplearray;

Trgbtriplearray = array [0 .. 1024-1] of trgbtriple;

VaR

Row: prgbtriparray;

P: trgbtriple;

Access column x (x, y) of row y)

Row: = BMP. scanline [y];

P: = row [x];

R: = P. rgbtred;

G: = P. rgbtgreen;

B: = P. rgbtblue;

Another access method

VaR

P: pbytearray;

Access column x (x, y) of row y)

P: = BMP .. scanline [y];

Use P [x * 3], p [x * 3 + 1], P [x * 3 + 2] for access

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.