程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> WinAPI: GetPath - 獲取路徑中的點

WinAPI: GetPath - 獲取路徑中的點

編輯:Delphi

本例效果圖:

WinAPI: GetPath - 獲取路徑中的點

  代碼文件:

unit Unit1; 
 
interface 
 
uses 
 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
 Dialogs, StdCtrls, ExtCtrls; 
 
type 
 TForm1 = class(TForm) 
  Memo1: TMemo; 
  procedure FormPaint(Sender: TObject); 
 end; 
 
var 
 Form1: TForm1; 
 
implementation 
 
{$R *.dfm} 
 
procedure TForm1.FormPaint(Sender: TObject); 
type 
 TPArr = array[0..0] of TPoint; 
 TTArr = array[0..0] of Byte; 
var 
 pts: ^TPArr; 
 types: ^TTArr; {上面四行只是為了記錄數據位置的起始點, 直接用指針也可以, 但用數組方便} 
 count: Integer; 
 i,x,y: Integer; 
begin 
 Canvas.Font.Size := 150; 
 Canvas.Font.Style := [fsBold]; 
 SetBkMode(Canvas.Handle, TRANSPARENT); 
 
 {路徑} 
 BeginPath(Canvas.Handle); 
 Canvas.TextOut(2, 0, '萬'); 
 EndPath(Canvas.Handle); 
 
 Canvas.Pen.Color := clWhite; 
 
 {GetPath 最後一個參數是 0, 可以先獲取點總數} 
 count := GetPath(Canvas.Handle, pts^, types^, 0); 
 
 {分配內存} 
 GetMem(pts, count*SizeOf(TPoint)); 
 GetMem(types, count); 
 
 {獲取點序列, 同時也獲取了點類型序列} 
 count := GetPath(Canvas.Handle, pts^, types^, count); 
 Text := '路徑中點的總數是: ' + IntToStr(count); 
 
 {路徑描邊} 
 StrokePath(Canvas.Handle); 
 
 Memo1.Clear; 
 Canvas.Brush.Color := clRed; 
 
 {顯示和繪制點序列} 
 for i := 0 to count - 1 do 
 begin 
  x := pts^[i].X; 
  y := pts^[i].Y; 
  Memo1.Lines.Add(Format('x:%d;' + #9 + 'y:%d', [x, y])); 
  Canvas.FillRect(Rect(x-1,y-1,x+1,y+1)); 
 end; 
 
 {釋放內存} 
 FreeMem(pts); 
 FreeMem(types); 
end; 
 
end. 

  窗體文件:

object Form1: TForm1 
 Left = 329 
 Top = 269 
 Caption = 'Form1' 
 ClIEntHeight = 235 
 ClIEntWidth = 331 
 Color = clBtnFace 
 Font.Charset = DEFAULT_CHARSET 
 Font.Color = clWindowText 
 Font.Height = -11 
 Font.Name = 'Tahoma' 
 Font.Style = [] 
 OldCreateOrder = False 
 Position = poDesigned 
 OnPaint = FormPaint 
 PixelsPerInch = 96 
 TextHeight = 13 
 object Memo1: TMemo 
  Left = 216 
  Top = 0 
  Width = 115 
  Height = 235 
  Align = alRight 
  Lines.Strings = ( 
   'Memo1') 
  ScrollBars = ssBoth 
  TabOrder = 0 
  ExplicitHeight = 264 
 end 
end 


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved