C-language version of GDI + application example-colormatrix

Source: Internet
Author: User

This example shows several typical applications of the colormatrix of GDI +:

# Include ".. /.. /samplecode/comcode/application. H "</P> <p> # pragma hdrstop </P> <p> # defineid_rease100 <br/> # defineid_alpha101 <br/> # defineid_bright102 <br/> # defineid_gray103 <br/> # define id_two104 <br/> # defineid_invert105 </P> <p> pgpbitmap bitmap; <br/> pgpimageattr ATTR; <br/> rect drect; <br/> hfont = NULL; </P> <p> void createbutton (lptstr caption, int top, int Itemid, hfont) <br/>{< br/> hwnd hbutton = createwindow (text ("button"), caption, ws_child | ws_visible, <br/> 488, top, 80, 25, handle, (hmenu) Itemid, hinstance, null); <br/> sendmessage (hbutton, wm_setfont, (wparam) (hfont), 0 ); <br/>}</P> <p> void oncreate (void) <br/> {<br/> hfont = createfont (14, 0, 0, 0, fw_normal, <br/> false, gb2312_charset, out_default_precis, <br/> clip_default_precis, default_quality, ff_decorative, text (" ")); </P> <p> createbutton (text ("Translucent"), 30, id_alpha, hfont); <br/> createbutton (text ("brightness 20%"), 65, id_bright, hfont); <br/> createbutton (text ("grayscale"), 100, id_gray, hfont ); <br/> createbutton (text ("binarization"), 135, id_two, hfont); <br/> createbutton (text ("Reversed"), 170, id_invert, hfont); <br/> createbutton (text ("reset"), 205, id_rease, hfont); </P> <p> bitmap = bitmapfromfile (L ".. //.. // media // source.jpg ", false); <br/> ATTR = imageattrcreate (); <br/> drect = makerect (0, 0, imagegetwidth (Bitmap ), imagegetheight (Bitmap); <br/>}</P> <p> void ondestroy (void) <br/>{< br/> If (hfont) <br/> deleteobject (hfont); <br/> imagedelete (Bitmap); <br/> imageattrdelete (ATTR ); <br/>}</P> <p> void oncommand (word policycode, word Itemid, hwnd ctlhandle) <br/>{< br/> colormatrix matrix; <br/> int I; <br/> memset (& matrix, 0, sizeof (colormatrix); <br/> for (I = 0; I <5; I ++) <br/> matrix. M [I] [I] = 1.0f; <br/> imageattrreset (ATTR, coloradjusttypedefault); <br/> switch (Itemid) <br/>{< br/> case id_rease: <br/> invalidaterect (handle, & drect, false); <br/> return; <br/> case id_alpha: <br/> matrix. M [3] [3] = 0.5f; <br/> break; <br/> case id_bright: <br/> matrix. M [4] [0] = matrix. M [4] [1] = matrix. M [4] [2] = 0.2f; <br/> break; <br/> case id_gray: <br/> case id_two: <br/> matrix. M [0] [0] = matrix. M [0] [1] = matrix. M [0] [2] = 0.30f; <br/> matrix. M [1] [0] = matrix. M [1] [1] = matrix. M [1] [2] = 0.59f; <br/> matrix. M [2] [0] = matrix. M [2] [1] = matrix. M [2] [2] = 0.11f; <br/> break; <br/> case id_invert: <br/> matrix. M [0] [0] = matrix. M [1] [1] = matrix. M [2] [2] =-1.0f; <br/> break; <br/>}< br/> imageattrsetcolormatrix (ATTR, & matrix, colormatrixflagsdefault, coloradjusttypedefault ); <br/> If (Itemid = id_two) <br/> imageattrsetthreshold (ATTR, 0.5, coloradjusttypedefault); <br/> invalidaterect (handle, & drect, false ); <br/>}</P> <p> void onpaint (hdc dc) <br/>{< br/> pgpgraphics G = graphicscreate (DC ); // GDI + canvas <br/> graphicsdrawimagerectrect (G, bitmap, & drect, 0, 0, drect. width, drect. height, unitpixel, ATTR); <br/> graphicsdelete (g); <br/>}</P> <p> winapi winmain (hinstance, hinstance hprevinstance, lpstr lpcmdline, int ncmdshow) <br/>{< br/> // The Double Buffer painting window is used here */<br/> initapplication (hinstance, ncmdshow, true ); <br/> createproc = oncreate; <br/> destroyproc = ondestroy; <br/> paintproc = onpaint; <br/> commandproc = oncommand; <br/> return runapplication (text ("C language gdiplus demo -- colormatrix"), 582,392); <br/>}< br/> // example //---------------------------------------------------------------------------

For the window framework code used by the example code and the GDI + C language version, see "using GDI + in C Windows Applications".

The following figure shows the example running interface:

For more information about GDI + colormatrix, see the complete secrets of GDI + colormatrix and the color adjustment matrix colormatrix basics of GDI + for VCL.

Please send to: mao.maozefa@gmail.com, maozefa@hotmail.com

 

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.