Gdiplus [60]: more methods for image (12) igpimageattributes

Source: Internet
Author: User
Tags transparent color
Igpimageattributes method:
Setwrapmode () {set surround mode} This is the unique method except clone in igpimageattributes that is irrelevant to the color.
 Setthreshold (), setthreshold () {set, cancel "threshold"} value range: 0 .. 1. If the threshold value is set to 0.5, the values in red that exceed 128 will change to 256, and the values in red that are less than 128 will change to 0. This is also true for green and blue.
 Setremaptable (), clearremaptable (), setbrushremaptable (), clearbrushremaptable {set and cancel "color ing table"} is to replace the specified color with another color. Its main parameter is an array, multiple colors can be replaced. setbrushremaptable and clearbrushremaptable are used for image painting of metafiles. setremaptable can also be used to complete the setbrushremaptable task. Therefore, setbrushremaptable is redundant.
 Setcolorkey (), clearcolorkey () {set, cancel transparent color range} if only one transparent color is specified, you can set the two parameters to the same value.
 Setgamma (), cleargamma () {You can use setgamma () or cleargamma () to set or cancel a Gamma Correction Value (or Grayscale Correction Value)} to adjust the brightness. The value range is 0. 1. 5. The default value is 1.
 Setoutputchannel () and clearoutputchannel () {set and cancel CMYK output channel}. The effect of the CMYK (cyan, magenta, yellow, and black) channels is gray, which is actually the color intensity.
 Settoidentity (), reset () {reset (reply to the default value)} is reset, it is recommended to use settoidentity to reset the specified type, and use reset to reset all. setnoop () and clearnoop () {disable and disable setnoop (that is, reuse )}
 Getadjustedpalette () {retrieve the converted color palette} even after the color transformation, the color palette obtained from igpimage is still original. igpimageattributes. getadjustedpalette () is required to obtain the changed color palette ().
 Setcolormatrix (), clearcolormatrix () {set, cancel Color adjustment matrix} setcolormatrices (), clearcolormatrices () {set and cancel the color adjustment matrix and grayscale adjustment matrix} There are two matrices in the setcolormatrices parameter. The former is used for the color matrix and the latter is used for the gray matrix. the third parameter of setcolormatrices requires an enumerated value of the tgpcolormatrixflags type: tgpcolormatrixflags = (colormatrixflagsdefault: // only adjust the color and grayscale using the first matrix, which is the same as using setcolormatrix; effect: // adjust only the color matrix and ignore the second matrix. colormatrixflagsaltgray: // adjust only the gray matrix. At this time, a matrix is ignored .);
 Setoutputchannelcolorprofile (), clearoutputchannelcolorprofile () {set and cancel the color configuration file} *. ICC or *. ICM; default path: .. windows \ system32 \ spool \ drivers \ color \
 

Except setwrapmode, setbrushremaptable, and clearbrushremaptable,
Each has a tgpcoloradjusttype parameter:

Tgpcoloradjusttype = (coloradjusttypedefault, // default, applicable to various types of coloradjusttypebitmap, // used for bitmap coloradjusttypebrush, // used to paint coloradjusttypepen in the Metafile, // used to paint the coloradjustpetext in the Metafile, // coloradjusttypecount, // useless coloradjusttypeany // reserved) for text in the Metafile; // If coloradjusttypedefault is used, then the conversion will apply to various types (bitmap, paint brush, image brush, etc.); // After the default is used, if the conversion is specified separately, of course, it will not use the default value, but after clear, the system will fail to return to default.
 

Wrapmodetile test:


Uses gdiplus; Procedure tform1.formpaint (Sender: tobject); var graphics: igpgraphics; IMG: igpimage; ATTR: igpimageattributes; rect: tgprect; begin graphics: = tgpgraph. create (handle); IMG: = tgpimage. create ('C: \ gdiplusimg \ bird.bmp '); rect. initialize (4, 4, IMG. width, IMG. height); ATTR: = tgpimageattributes. create; {Original} graphics. drawimage (IMG, rect, 0, 0, IMG. width, IMG. height, unitpixel, nil); {wrapmodetile} ATTR. setwrapmode (wrapmodetile); graphics. translatetransform (rect. width + rect. x, 0); graphics. drawimage (IMG, rect, 0, 0, IMG. width * 2, IMG. height * 2, unitpixel, ATTR); {wrapmodetileflipx} ATTR. setwrapmode (wrapmodetileflipx); graphics. translatetransform (rect. width + rect. x, 0); graphics. drawimage (IMG, rect, 0, 0, IMG. width * 2, IMG. height * 2, unitpixel, ATTR); {wrapmodetileflipy} ATTR. setwrapmode (wrapmodetileflipy); graphics. translatetransform (rect. width + rect. x, 0); graphics. drawimage (IMG, rect, 0, 0, IMG. width * 2, IMG. height * 2, unitpixel, ATTR); {wrapmodetileflipxy} ATTR. setwrapmode (wrapmodetileflipxy); graphics. translatetransform (rect. width + rect. x, 0); graphics. drawimage (IMG, rect, 0, 0, IMG. width * 2, IMG. height * 2, unitpixel, ATTR); {wrapmodeclamp} ATTR. setwrapmode (wrapmodeclamp); graphics. translatetransform (rect. width + rect. x, 0); graphics. drawimage (IMG, rect, 0, 0, IMG. width * 2, IMG. height * 2, unitpixel, ATTR); end;
 

Setthreshold test:


Uses gdiplus; Procedure tform1.formpaint (Sender: tobject); const colors: array [0 .. 6] of cardinal = ($ ffff0000, $ ff00ff00, $ ff0000ff, $ ffffff00, $ ffff00ff, $ ff00ffff, $ ff000000); var graphics, graphicsimg: igpgraphics; IMG: igpimage; ATTR: igpimageattributes; rect: tgprect; I: integer; F: single; begin {no suitable image, first draw a color gradient image} IMG: = tgpbitmap. create (80,140); graphicsimg: = tgpgraphics. create (IMG); for I: = 0 to 6 do begin rect. initialize (0, I * IMG. height Div 7, IMG. width, IMG. height Div 7); graphicsimg. fillrectangle (tgplineargradientbrush. create (rect, colors [I], $ ffffffff, 0), rect); end; graphics: = tgpgraphics. create (handle); graphics. fillrectangle (tgphatchbrush. create (hatchstylediagonalcross, $ ffd0d0d0, $ ff606060), tgprect. create (clientrect); rect. initialize (12, 6, IMG. width, IMG. height); ATTR: = tgpimageattributes. create; {Original} graphics. drawimage (IMG, rect, 0, 0, IMG. width, IMG. height, unitpixel, nil); {setthreshold} f: = 0; while F

Setremaptable and setbrushremaptable test:


Uses gdiplus; Procedure injection (Sender: tobject); var graphics, graphicsimg: igpgraphics; IMG: igpimage; ATTR: igpimageattributes; rect: tgprectf; colormaparr: array [0 .. 1] of tgpcolormap; begin graphics: = tgpgraphics. create (handle); IMG: = tgpimage. create ('C: \ gdiplusimg \ samplemetafile. emf'); rect. initialize (10, 10, IMG. width * 0.75, IMG. height * 0.75); ATTR: = tgpimageattributes. create; {Original} graphics. drawimage (IMG, rect, 0, 0, IMG. width, IMG. height, unitpixel, nil); {setremaptable: replace blue with black and green with red} colormaparr [0]. oldcolor: = $ ff0000ff; colormaparr [0]. newcolor: = $ ff000000; colormaparr [1]. oldcolor: = $ ff00ff00; colormaparr [1]. newcolor: = $ ffff0000; ATTR. setremaptable (colormaparr); graphics. translatetransform (rect. width + rect. x, 0); graphics. drawimage (IMG, rect, 0, 0, IMG. width, IMG. height, unitpixel, ATTR); ATTR. clearremaptable (); ATTR. setbrushremaptable (colormaparr); {This is the same as the effect of the following row} // ATTR. setremaptable (colormaparr, coloradjusttypebrush); graphics. translatetransform (rect. width + rect. x, 0); graphics. drawimage (IMG, rect, 0, 0, IMG. width, IMG. height, unitpixel, ATTR); ATTR. clearbrushremaptable; end;
 

Setcolorkey test:


Uses gdiplus; Procedure injection (Sender: tobject); var graphics, graphicsimg: igpgraphics; IMG: igpimage; ATTR: igpimageattributes; rect: tgprect; begin graphics: = tgpgraphics. create (handle); IMG: = tgpimage. create ('C: \ gdiplusimg \ bird.bmp '); rect. initialize (10, 10, IMG. width, IMG. height); ATTR: = tgpimageattributes. create; graphics. fillrectangle (tgphatchbrush. create (hatchstylediagonalcross, $ ffc0c0c0, $ ffe0e0e0), tgprect. create (clientrect); {Original} graphics. drawimage (IMG, rect, 0, 0, IMG. width, IMG. height, unitpixel, nil); // ATTR. setcolorkey ($ ffffffff, $ ffffffff); graphics. translatetransform (rect. width + rect. x, 0); graphics. drawimage (IMG, rect, 0, 0, IMG. width, IMG. height, unitpixel, ATTR); // ATTR. setcolorkey ($ ff003399, $ ff3366cc); graphics. translatetransform (rect. width + rect. x, 0); graphics. drawimage (IMG, rect, 0, 0, IMG. width, IMG. height, unitpixel, ATTR); // ATTR. setcolorkey ($ ff003399, $ ffffffff); graphics. translatetransform (rect. width + rect. x, 0); graphics. drawimage (IMG, rect, 0, 0, IMG. width, IMG. height, unitpixel, ATTR); end;
 

Setgamma test:


Uses gdiplus; Procedure injection (Sender: tobject); var graphics, graphicsimg: igpgraphics; IMG: igpimage; ATTR: signature; rect: tgprectf; F: single; begin graphics: = tgpgraphics. create (handle); IMG: = tgpimage. create ('C: \ gdiplusimg \ grapes.jpg '); rect. initialize (4, 4, IMG. width/2, IMG. height/2); ATTR: = tgpimageattributes. create; {Original} graphics. drawimage (IMG, rect, 0, 0, IMG. width, IMG. height, unitpixel, nil); F: = 0.25; while F

Setoutputchannel test:


Uses gdiplus; Procedure injection (Sender: tobject); var graphics, graphicsimg: igpgraphics; IMG: igpimage; ATTR: signature; rect: tgprect; I: integer; begin graphics: = tgpgraphics. create (handle); IMG: = tgpimage. create ('C: \ gdiplusimg \ bird.bmp '); rect. initialize (4, 4, IMG. width, IMG. height); ATTR: = tgpimageattributes. create; {Original} graphics. drawimage (IMG, rect, 0, 0, IMG. width, IMG. height, unitpixel, nil); for I: = 0 to 3 do begin ATTR. setoutputchannel (tgpcolorchannelflags (I); graphics. translatetransform (rect. width + rect. x, 0); graphics. drawimage (IMG, rect, 0, 0, IMG. width, IMG. height, unitpixel, ATTR); end;
 

Settoidentity test:


Uses gdiplus; Procedure injection (Sender: tobject); var graphics, graphicsimg: igpgraphics; IMG: igpimage; ATTR: igpimageattributes; rect: tgprectf; colormaparr: array [0 .. 1] of tgpcolormap; begin graphics: = tgpgraphics. create (handle); IMG: = tgpimage. create ('C: \ gdiplusimg \ samplemetafile. emf'); rect. initialize (4, 4, IMG. width * 0.7, IMG. height * 0.7); ATTR: = tgpimageattributes. create; colormaparr [0]. oldcolor: = $ ff00ff00; colormaparr [0]. newcolor: = $ ffff0000; colormaparr [1]. oldcolor: = $ ff0000ff; colormaparr [1]. newcolor: = $ ff000000; {Original} graphics. drawimage (IMG, rect, 0, 0, IMG. width, IMG. height, unitpixel, nil); {set color replacement (including paint brush and paint brush by default)} ATTR. setremaptable (colormaparr); graphics. translatetransform (rect. width + rect. x, 0); graphics. drawimage (IMG, rect, 0, 0, IMG. width, IMG. height, unitpixel, ATTR); {reset the brush transform} ATTR. settoidentity (coloradjusttypepen); graphics. translatetransform (rect. width + rect. x, 0); graphics. drawimage (IMG, rect, 0, 0, IMG. width, IMG. height, unitpixel, ATTR); {reset the image brush transform} ATTR. settoidentity (coloradjusttypebrush); graphics. translatetransform (rect. width + rect. x, 0); graphics. drawimage (IMG, rect, 0, 0, IMG. width, IMG. height, unitpixel, ATTR); end;
 

Setnoop, clearnoop, and reset test:


Uses gdiplus; Procedure injection (Sender: tobject); var graphics, graphicsimg: igpgraphics; IMG: igpimage; ATTR: igpimageattributes; rect: tgprectf; begin graphics: = tgpgraph. create (handle); IMG: = tgpimage. create ('C: \ gdiplusimg \ grapes.jpg '); rect. initialize (4, 4, IMG. width * 0.75, IMG. height * 0.75); ATTR: = tgpimageattributes. create; {Original} graphics. drawimage (IMG, rect, 0, 0, IMG. width, IMG. height, unitpixel, nil); {transform} ATTR. setgamma (0.3); graphics. translatetransform (rect. width + rect. x, 0); graphics. drawimage (IMG, rect, 0, 0, IMG. width, IMG. height, unitpixel, ATTR); {disable the specified (here is the default) color conversion} ATTR. setnoop (); graphics. translatetransform (rect. width + rect. x, 0); graphics. drawimage (IMG, rect, 0, 0, IMG. width, IMG. height, unitpixel, ATTR); {disable} ATTR. clearnoop (); graphics. translatetransform (rect. width + rect. x, 0); graphics. drawimage (IMG, rect, 0, 0, IMG. width, IMG. height, unitpixel, ATTR); {reset} ATTR. reset (); graphics. translatetransform (rect. width + rect. x, 0); graphics. drawimage (IMG, rect, 0, 0, IMG. width, IMG. height, unitpixel, ATTR); end;
 

Getadjustedpalette test:


Uses gdiplus; Procedure injection (Sender: tobject); var graphics, graphicsimg: igpgraphics; IMG: igpimage; ATTR: igpimageattributes; rect: tgprect; colormaparr: array [0 .. 2] of tgpcolormap; colorpalette: igpcolorpalette; I: integer; brush: igpsolidbrush; begin IMG: = tgpimage. create ('C: \ gdiplusimg \ stripes.bmp '); if not isindexedpixelformat (IMG. pixelformat) Then exit; graphics: = tgpgraphics. create (handle); rect. initialize (10, 10, IMG. width, IMG. height); ATTR: = tgpimageattributes. create; graphics. fillrectangle (tgphatchbrush. create (hatchstylediagonalcross, $ ffc0c0c0, $ ffe0e0e0), tgprect. create (clientrect); {Original} graphics. drawimage (IMG, rect, 0, 0, IMG. width, IMG. height, unitpixel, nil); {setremaptable} colormaparr [0]. oldcolor: = $ ffff0000; colormaparr [0]. newcolor: = $ ff800000; colormaparr [1]. oldcolor: = $ ff00ff00; colormaparr [1]. newcolor: = $ ff008000; colormaparr [2]. oldcolor: = $ ff0000ff; colormaparr [2]. newcolor: = $ ff000080; ATTR. setremaptable (colormaparr); rect. offset (rect. width + rect. x, 0); graphics. drawimage (IMG, rect, 0, 0, IMG. width, IMG. height, unitpixel, ATTR); {color of the color palette in the source image} rect. offset (-rect. X + 10, rect. height + 10); rect. width: = 15; rect. height: = 15; brush: = tgpsolidbrush. create (0); colorpalette: = IMG. palette; for I: = 0 to colorpalette. count-1 do begin brush. color: = colorpalette. entries [I]; graphics. fillrectangle (brush, rect); rect. offset (20, 0); end; {color of the color palette after enumeration transformation} rect. x: = IMG. width + 20; ATTR. getadjustedpalette (colorpalette, coloradjusttypebitmap); for I: = 0 to colorpalette. count-1 do begin brush. color: = colorpalette. entries [I]; graphics. fillrectangle (brush, rect); rect. offset (20, 0); end;
 

Setcolormatrices test:


Uses gdiplus; Procedure injection (Sender: tobject); var graphics: igpgraphics; IMG: igpimage; ATTR: signature; colormatrix: tgpcolormatrix; rect: tgprectf; begin graphics: = tgpgraphics. create (handle); graphics. fillrectangle (tgpsolidbrush. create ($ ffff0000), tgprect. create (clientrect); IMG: = tgpimage. create ('C: \ gdiplusimg \ bird.bmp '); rect. initialize (4, 4, IMG. width, IMG. height); ATTR: = tgpimageattributes. create; {Original Image} graphics. drawimage (IMG, rect, 0, 0, IMG. width, IMG. height, unitpixel, nil); colormatrix. settoidentity; colormatrix. M [0, 0]: = 1.5; colormatrix. M [1, 1]: = 1; colormatrix. M [2, 2]: = 0.5; {transformations include RGB and grayscale} ATTR. setcolormatrices (colormatrix, colormatrix, colormatrixflagsdefault); graphics. translatetransform (rect. width + rect. x, 0); graphics. drawimage (IMG, rect, 0, 0, IMG. width, IMG. height, unitpixel, ATTR); {transform only RGB} ATTR. setcolormatrices (colormatrix, colormatrix, colormatrixflagsskipgrays); graphics. translatetransform (rect. width + rect. x, 0); graphics. drawimage (IMG, rect, 0, 0, IMG. width, IMG. height, unitpixel, ATTR); {transform only grayscale} ATTR. setcolormatrices (colormatrix, colormatrix, colormatrixflagsaltgray); graphics. translatetransform (rect. width + rect. x, 0); graphics. drawimage (IMG, rect, 0, 0, IMG. width, IMG. height, unitpixel, ATTR); 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.