By color to black and white

xiaoxiao2021-04-08  412

Mythma

Color chart is converted to grayscale formula very simple:

Y = 0.3red 0.59green 0.11

Blue

The way to use GDI is used in two: 1. Modify the pixel point directly with the above formula 2. Use ColorMatrix. Below is an example of implementing the ColorMatrix:

Using

Namespace

GDIPLUS; Image IMG (WSZFileName); Graphics Graphics (Getdc ()

->

GetsafeHDC ()); ColorMatrix CM

=

{0.3F, 0.3F, 0.3F, 0, 0, 0.59F, 0.59F, 0.59F, 0, 0, 0.11F, 0.11F, 0.11F, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1}

ImageAttributes IA; IA.SETColorMatrix

&

cm);

Float

x

=

(

Float

) img.getwidth ();

Float

y

=

(

Float

) img.getheight (); graphics.drawimage

&

IMG, Rectf

0.0F

,

0.0F

, x, y,

0.0F

,

0.0F

, X, Y, Unitpixel,

&

IA);

转载请注明原文地址:https://www.9cbs.com/read-132699.html

New Post(0)