Re-learning gdi+[95]: tgpimage (15)

Source: Internet
Author: User

By doing this example, I also confirmed that GDI + can directly display transparent pictures in PNG, GIF, and TIF format.

//红色与绿色绕蓝色旋转(r 是弧度)
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));
//绿色与蓝色绕红色旋转(r 是弧度)
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));
//红色与蓝色绕绿色旋转(r 是弧度)
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));
This example effect chart:

Code files:Unit Unit1;
Interface
Uses
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 Formpaint (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 around Blue spin ');
ADD (' Red and blue around green rotation ');
ADD (' green and blue rotate around red ');
End
Radiogroup1.itemindex: = 0;
DoubleBuffered: = True;
End
Procedure Tform1.formpaint (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; {Radians by angle}
ColorMatrix: = Matrix; {Reply to default value}
Case Radiogroup1.itemindex of
0:begin {red and green rotate around blue}
colormatrix[0,0]: = Cos (R);
colormatrix[0,1]: = Sin (R);
colormatrix[1,0]: =-sin (R);
colormatrix[1,1]: = Cos (R);
End
1:begin {red and blue around green rotation}
colormatrix[0,0]: = Cos (R);
colormatrix[0,2]: = Sin (R);
colormatrix[2,0]: =-sin (R);
colormatrix[2,2]: = Cos (R);
End
2:begin {green and blue rotate around red}
colormatrix[1,1]: = Cos (R);
colormatrix[1,2]: = Sin (R);
colormatrix[2,1]: =-sin (R);
colormatrix[2,2]: = Cos (R);
End
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 Tform1.radiogroup1click (Sender:tobject);
Begin
Repaint;
End
Procedure Tform1.trackbar1change (Sender:tobject);
Begin
Repaint;
End
Procedure Tform1.checkbox1click (Sender:tobject);
Begin
Repaint;
End
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
 end
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.