• 再学 GDI+[68]: 路径画刷(8) SetBlendTriangularShaped、SetBlendBellShape


    本例效果图(颜色失真严重, 因为 GIF 最多只能接受 256 中颜色):



    代码文件:
    unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, ComCtrls, StdCtrls, ExtCtrls;
    
    type
      TForm1 = class(TForm)
        TrackBar1: TTrackBar;
        TrackBar2: TTrackBar;
        RadioGroup1: TRadioGroup;
        procedure FormCreate(Sender: TObject);
        procedure FormPaint(Sender: TObject);
        procedure RadioGroup1Click(Sender: TObject);
        procedure TrackBar1Change(Sender: TObject);
        procedure TrackBar2Change(Sender: TObject);
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    uses GDIPOBJ, GDIPAPI;
    
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      TrackBar1.Max := 100;
      TrackBar2.Max := 100;
      TrackBar1.Position := TrackBar1.Max;
      TrackBar2.Position := TrackBar2.Max;
      TrackBar1.ShowSelRange := False;
      TrackBar2.ShowSelRange := False;
      TrackBar1.Height := 23;
      TrackBar2.Height := 23;
    
      RadioGroup1.Items.CommaText := 'BlendTriangularShape, SetBlendBellShape';
      RadioGroup1.ItemIndex := 0;
    
      DoubleBuffered := True;
    end;
    
    procedure TForm1.FormPaint(Sender: TObject);
    const
      colors: array[0..0] of TGPColor = (aclRed);
    var
      g: TGPGraphics;
      path: TGPGraphicsPath;
      pb: TGPPathGradientBrush;
      num: Integer;
    begin
      g := TGPGraphics.Create(Canvas.Handle);
      path := TGPGraphicsPath.Create;
      path.AddRectangle(MakeRect(30,10,160,150));
      pb:= TGPPathGradientBrush.Create(path);
    
      num := Length(colors);
      pb.SetSurroundColors(@colors, num);
    
      pb.SetCenterColor(aclYellow);
    
      {SetBlendTriangularShape 与 SetBlendBellShape 参数2的默认值都是 1.0}
      case RadioGroup1.ItemIndex of
        0: pb.SetBlendTriangularShape(TrackBar1.Position/100, TrackBar2.Position/100);
        1: pb.SetBlendBellShape(TrackBar1.Position/100, TrackBar2.Position/100);
      end;
    
      g.FillPath(pb, path);
    
      pb.Free;
      path.Free;
      g.Free;
    end;
    
    procedure TForm1.RadioGroup1Click(Sender: TObject);
    begin
      Repaint;
    end;
    
    procedure TForm1.TrackBar1Change(Sender: TObject);
    begin
      Repaint;
    end;
    
    procedure TForm1.TrackBar2Change(Sender: TObject);
    begin
      Repaint;
    end;
    
    end.
    
    窗体文件:
    object Form1: TForm1
      Left = 0
      Top = 0
      Caption = 'Form1'
      ClientHeight = 261
      ClientWidth = 221
      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 = 0
        Top = 167
        Width = 113
        Height = 45
        TabOrder = 0
        OnChange = TrackBar1Change
      end
      object TrackBar2: TTrackBar
        Left = 108
        Top = 167
        Width = 113
        Height = 45
        TabOrder = 1
        OnChange = TrackBar2Change
      end
      object RadioGroup1: TRadioGroup
        Left = 8
        Top = 192
        Width = 206
        Height = 61
        Caption = 'RadioGroup1'
        TabOrder = 2
        OnClick = RadioGroup1Click
      end
    end
    
  • 相关阅读:
    已知圆心,半径,角度,求圆上的点坐标
    js-JavaScript高级程序设计学习笔记10
    js-关于性能优化的一些学习总结
    css-css权威指南学习笔记2
    css-a与a:link的一些认识
    css-IE中的border-radius和box-shadow
    css-css权威指南学习笔记1
    css-文本超出后显示省略号
    js-JavaScript高级程序设计学习笔记9
    js-JavaScript高级程序设计学习笔记8
  • 原文地址:https://www.cnblogs.com/del/p/1231826.html
Copyright © 2020-2023  润新知