By doing this, I also confirmed that GDI + can directly display transparent images in PNG, GIF, and TIF formats.
// Red and green rotate around blue (R is radian) colormatrix: tcolormatrix = (COS (R), sin (R), 0.0, 0.0, 0.0 ), (-sin (R), cos (R), 0.0, 0.0, 0.0), (0.0, 0.0, 1.0, 0.0, 0.0), (0.0, 0.0, 0.0, 1.0, 0.0), (0.0, 0.0, 0.0, 0.0, 1.0); // rotate green and blue (R is a radian) colormatrix: tcolormatrix = (0.0, 0.0, 0.0, 0.0, 0.0), (0.0, cos (R), sin (R), 0.0, 0.0), (0.0,-sin (R), cos (R ), 0.0, 0.0), (0.0, 0.0, 0.0, 1.0, 0.0), (0.0, 0.0, 0.0, 0.0, 1.0 )); // red and blue rotate Green (R is radian) colormatrix: tcolormatrix = (COS (R), 0.0, sin (R), 0.0, 0.0 ), (-sin (R), 0.0, cos (R), 0.0, 0.0), (0.0, 0.0, 1.0, 0.0, 0.0), (0.0, 0.0, 0.0, 1.0, 0.0), (0.0, 0.0, 0.0, 0.0, 1.0 ));
In this example:
Code file:
Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls, comctrls, extctrls; Type tform1 = Class (tform) trackbar1: ttrackbar; radiogroup1: tradiogroup; Procedure formcreate (Sender: tobject); Procedure submit (Sender: tobject); Procedure checkbox1click (Sender: tobject); Procedure trackbar1change (Sender: tobject ); procedure radiogroup1click (Sender: tobject); end; var form1: tform1; implementation {$ R *. DFM} uses gdipobj, gdipapi; const matrix: tcolormatrix = (1.0, 0.0, 0.0, 0.0, 0.0), (0.0, 1.0, 0.0, 0.0, 0.0), (0.0, 0.0, 1.0, 0.0, 0.0), (0.0, 0.0, 0.0, 1.0, 0.0), (0.0, 0.0, 0.0, 0.0, 1.0); Procedure tform1.formcreate (Sender: tobject); begin trackbar1.height: = 23; trackbar1.showselrange: = false; trackbar1.min: =-180; trackbar1.max: = 180; trackbar1.position: = 0; with radiogroup1.items do begin add ('red and green Rotate blue '); add ('red and blue rotate green'); add ('green and blue rotate red '); end; radiogroup1.itemindex: = 0; doublebuffered: = true; end; Procedure submit (Sender: tobject); var G: tgpgraphics; IMG: tgpimage; imageattributes: tgpimageattributes; R: single; colormatrix: tcolormatrix; begin G: = tgpgraphics. create (canvas. handle); IMG: = tgpimage. create ('C: \ temp \ test.png '); imageattributes: = tgpimageattributes. create; R: = trackbar1.position * PI/180; {calculate radians Based on angle} colormatrix: = matrix; {reply default value} case radiogroup1.itemindex of 0: begin {red and green rotate around Blue} colormatrix []: = cos (r); colormatrix []: = sin (r); colormatrix []: =-sin (r); colormatrix []: = cos (r); end; 1: begin {red and blue rotate around green} colormatrix []: = cos (r); colormatrix []: = sin (r); colormatrix []: =-sin (r); colormatrix []: = cos (R ); end; 2: begin {green and blue rotate around red} colormatrix []: = cos (r); colormatrix []: = sin (r); colormatrix []: =-sin (r); colormatrix [2, 2]: = cos (r); end; imageattributes. setcolormatrix (colormatrix); G. drawimage (IMG, makerect (4, 4, IMG. getwidth, IMG. getheight), 0, 0, IMG. getwidth, IMG. getheight, unitpixel, imageattributes); imageattributes. free; IMG. free; G. free; end; Procedure extract (Sender: tobject); begin repaint; end; Procedure tform1.trackbar1change (Sender: tobject); begin repaint; end; Procedure tform1.checkbox1click (Sender: tobject ); begin repaint; end.
Form file:
object Form1: TForm1 Left = 0 Top = 0 Caption = 'Form1' ClientHeight = 290 ClientWidth = 208 Color = clBtnFace Font.Charset = DEFAULT_CHARSET Font.Color = clWindowText Font.Height = -11 Font.Name = 'Tahoma' Font.Style = [] OldCreateOrder = False Position = poDesktopCenter OnCreate = FormCreate OnPaint = FormPaint PixelsPerInch = 96 TextHeight = 13 object TrackBar1: TTrackBar Left = 3 Top = 170 Width = 202 Height = 22 TabOrder = 0 OnChange = TrackBar1Change end object RadioGroup1: TRadioGroup Left = 8 Top = 198 Width = 190 Height = 83 Caption = 'RadioGroup1' TabOrder = 1 OnClick = RadioGroup1Click endend