再学 GDI+[17] FillRectangle、ColorRefToARGB、TGPSolidBrush 和颜色透明度

 

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    ColorListBox1: TColorListBox;
    TrackBar1: TTrackBar;
    procedure FormCreate(Sender: TObject);
    procedure FormPaint(Sender: TObject);
    procedure TrackBar1Change(Sender: TObject);
    procedure ColorListBox1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
uses
  GDIPOBJ,GDIPAPI;
procedure TForm1.ColorListBox1Click(Sender: TObject);
begin
  Repaint;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Self.Position:=poDesktopCenter;
  ColorListBox1.Align:=alRight;
  TrackBar1.Max:=255;
  TrackBar1.Min:=0;
  TrackBar1.ShowSelRange:=False;
  TrackBar1.PageSize:=20;
  TrackBar1.Position:=TrackBar1.Max;
end;

procedure TForm1.FormPaint(Sender: TObject);
var
  g:TGPGraphics;
  R:TGPRect;
  crl:TGPColor;
  alpha:Byte;
  sb:TGPSolidBrush;
begin
  Form1.DoubleBuffered:=True;
  g:=TGPGraphics.Create(Canvas.Handle);
  g.Clear(aclWhite);

  R:=MakeRect(20,20,250,200);
  crl:=ColorRefToARGB(ColorListBox1.Selected);
  alpha:=TrackBar1.Position;
  crl:=MakeColor(alpha,GetRed(crl),GetGreen(crl),GetBlue(crl));
  sb:=TGPSolidBrush.Create(crl);

  g.FillRectangle(sb,R);

  sb.Free;
  g.Free;
end;

procedure TForm1.TrackBar1Change(Sender: TObject);
begin
  Repaint;
  Text:=Format('透明度:%d',[TrackBar1.Position]);
end;

end.

转载于:https://www.cnblogs.com/keyvip/archive/2010/12/31/1922826.html

你可能感兴趣的:(再学 GDI+[17] FillRectangle、ColorRefToARGB、TGPSolidBrush 和颜色透明度)