文档章节

再学 GDI+[21]: TGPTextureBrush 与 TGPMatrix

涂孟超
 涂孟超
发布于 2014/09/26 15:36
字数 477
阅读 7
收藏 0
本例效果图:



代码文件:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Panel1: TPanel;
    Button1: TButton;
    TrackBar1: TTrackBar;
    TrackBar2: TTrackBar;
    TrackBar3: TTrackBar;
    TrackBar4: TTrackBar;
    TrackBar5: TTrackBar;
    TrackBar6: TTrackBar;
    procedure FormCreate(Sender: TObject);
    procedure FormPaint(Sender: TObject);
    procedure TrackBar1Change(Sender: TObject);
    procedure TrackBar2Change(Sender: TObject);
    procedure TrackBar3Change(Sender: TObject);
    procedure TrackBar4Change(Sender: TObject);
    procedure TrackBar5Change(Sender: TObject);
    procedure TrackBar6Change(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses GDIPOBJ, GDIPAPI;

procedure TForm1.FormCreate(Sender: TObject);
const
  n = 40;
begin
  TrackBar1.Min := -n;
  TrackBar1.Max := n;
  TrackBar2.Min := -n;
  TrackBar2.Max := n;
  TrackBar3.Min := -n;
  TrackBar3.Max := n;
  TrackBar4.Min := -n;
  TrackBar4.Max := n;
  TrackBar5.Min := -n;
  TrackBar5.Max := n;
  TrackBar6.Min := -n;
  TrackBar6.Max := n;

  TrackBar1.Position := 10;
  TrackBar2.Position := 0;
  TrackBar3.Position := 0;
  TrackBar4.Position := 10;
  TrackBar5.Position := 0;
  TrackBar6.Position := 0;

  Button1.OnClick := FormCreate;
end;

procedure TForm1.FormPaint(Sender: TObject);
var
  g: TGPGraphics;
  img: TGPImage;
  tb: TGPTextureBrush;
  matrix: TGPMatrix;
  m11, m12, m21, m22, dx, dy: Single;
begin
  g := TGPGraphics.Create(Canvas.Handle);
  img := TGPImage.Create('c:\temp\small.png');
  tb := TGPTextureBrush.Create(img);

  m11 := TrackBar1.Position / 10;
  m12 := TrackBar2.Position / 10;
  m21 := TrackBar3.Position / 10;
  m22 := TrackBar4.Position / 10;
  dx  := TrackBar5.Position * 10;
  dy  := TrackBar6.Position * 10;

  matrix := TGPMatrix.Create(m11, m12, m21, m22, dx, dy);
  tb.SetTransform(matrix);

  g.FillRectangle(tb, 0, 0, ClientWidth - Panel1.Width, ClientHeight);

  matrix.Free;
  img.Free;
  tb.Free;
  g.Free;
end;

procedure TForm1.TrackBar1Change(Sender: TObject);
begin
  Repaint;
end;

procedure TForm1.TrackBar2Change(Sender: TObject);
begin
  Repaint;
end;

procedure TForm1.TrackBar3Change(Sender: TObject);
begin
  Repaint;
end;

procedure TForm1.TrackBar4Change(Sender: TObject);
begin
  Repaint;
end;

procedure TForm1.TrackBar5Change(Sender: TObject);
begin
  Repaint;
end;

procedure TForm1.TrackBar6Change(Sender: TObject);
begin
  Repaint;
end;

end.

 
 
 
 
 

 

 

  
窗体文件:
object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 170
  ClientWidth = 324
  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 Panel1: TPanel
    Left = 225
    Top = 0
    Width = 99
    Height = 170
    Align = alRight
    TabOrder = 0
    ExplicitLeft = 288
    ExplicitHeight = 213
    object Button1: TButton
      Left = 14
      Top = 8
      Width = 75
      Height = 25
      Caption = #21021#22987#21270
      TabOrder = 0
    end
    object TrackBar1: TTrackBar
      Left = 0
      Top = 34
      Width = 100
      Height = 20
      ShowSelRange = False
      TabOrder = 1
      OnChange = TrackBar1Change
    end
    object TrackBar2: TTrackBar
      Left = 0
      Top = 56
      Width = 100
      Height = 20
      ShowSelRange = False
      TabOrder = 2
      OnChange = TrackBar2Change
    end
    object TrackBar3: TTrackBar
      Left = 0
      Top = 78
      Width = 100
      Height = 20
      ShowSelRange = False
      TabOrder = 3
      OnChange = TrackBar3Change
    end
    object TrackBar4: TTrackBar
      Left = 0
      Top = 100
      Width = 100
      Height = 20
      ShowSelRange = False
      TabOrder = 4
      OnChange = TrackBar4Change
    end
    object TrackBar5: TTrackBar
      Left = 0
      Top = 122
      Width = 100
      Height = 20
      ShowSelRange = False
      TabOrder = 5
      OnChange = TrackBar5Change
    end
    object TrackBar6: TTrackBar
      Left = 0
      Top = 144
      Width = 100
      Height = 20
      ShowSelRange = False
      TabOrder = 6
      OnChange = TrackBar6Change
    end
  end
end

 
 
 
 
 

 

 

  

本文转载自:http://www.cnblogs.com/del/archive/2008/06/11/1217378.html

共有 人打赏支持
涂孟超
粉丝 12
博文 2011
码字总数 14107
作品 0
深圳
程序员
私信 提问
实战开发:新手小白如何用C++制作经典网游DNF

十年前,那时候的网吧还不叫网咖,那时候没有王者荣耀也没有英雄联盟,那时候梦幻西游刚推出珍宝阁系统,那时候巫妖王的灵魂还封闭在冰封王座。 寻仙、穿越火线、征途、天龙八部……同时在线...

stone15165
05/05
0
0
EasyPlayerPro Windows播放器全屏模式下GDI显示出现黑屏问题解决

问题来源 2017.12.21 前天有杭州某教育领域客户反馈有部分视频源在全屏模式下显示黑屏; 问题复现 EasyPlayerPro由于没有实现单个窗口完全全屏,故没有暴露该问题,晚上加班,加上单个窗口完...

xiejiashu
2017/12/26
0
0
C# WinForm开发系列 - GDI+

UI(User Interface)编程在整个项目开发过程中是个颇为重要的环节,任何好的解决方案若没有良好的用户界面呈现给最终用户,那么就算包含了最先进的技术也不能算是好程序。UI编程体现在两个方...

长征2号
2017/11/14
0
0
VC 6.0 配置和使用gdi+

GDI+ GDI+是Windows XP中的一个子系统,它主要负责在显示屏幕和打印设备输出有关信息,它是一组通过C++类实现的应用程序编程接口。顾名思义,GDI+是以前版本GDI的继承者,出于兼容性考虑,W...

junwong
2012/03/23
1K
0
Windows的GDI映射方式,逻辑坐标,设备坐标的理解

最近在学Win32的编程,看的是《Windows程序设计第5版》一书,这本书是台湾人翻译的,有些译法和大陆不一样,书中还有一些错误的地方,很多时候需要中英文对照阅读,下载请点击 https://down...

蓝域小兵
08/18
0
0

没有更多内容

加载失败,请刷新页面

加载更多

w, vmstat, top, sar, nload命令查看系统状态信息

w/uptime 查看系统负载 cat /proc/cpuinfo 查看cpu核数 vmstat 监控系统状态,用法 vmstat 1,关键的几列: r, b, swpd, si, so, bi, bo, us, wa top 查看进程使用资源情况 top -c 显示详细的...

野雪球
今天
1
0
小白创建一个spring boot项目

进入 https://start.spring.io/

lilugirl
今天
2
0
Alibaba Java诊断利器Arthas实践--使用redefine排查应用奇怪的日志来源

背景 随着应用越来越复杂,依赖越来越多,日志系统越来越混乱,有时会出现一些奇怪的日志,比如: [] [] [] No credential found 那么怎样排查这些奇怪的日志从哪里打印出来的呢?因为搞不清...

hengyunabc
今天
2
0
home hosts

home hosts lwk@qwfys:~$ cat /etc/hosts127.0.0.1 localhost127.0.1.1 qwfys192.168.56.101vm600.qwfys.com39.108.212.91alpha1.ppy.com39.108.117.122alpha2.p......

qwfys
今天
3
0
大数据教程(6.1)hadoop生态圈介绍及就业前景

1. HADOOP背景介绍 1.1、什么是HADOOP 1.HADOOP是apache旗下的一套开源软件平台 2.HADOOP提供的功能:利用服务器集群,根据用户的自定义业务逻辑,对海量数据进行分布式处理 3.HADOOP的核心组...

em_aaron
今天
5
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部