Delphi完成圖象文本扭轉殊效完全實例代碼。本站提示廣大學習愛好者:(Delphi完成圖象文本扭轉殊效完全實例代碼)文章只能為提供參考,不一定能成為您想要的結果。以下是Delphi完成圖象文本扭轉殊效完全實例代碼正文
本文以實例講述了Delphi完成圖象文本扭轉殊效的處理辦法,在本法式中應用的控件重要是Panel 控件、Image 控件、Edit 控件、Label 控件和Button 控件。本法式的症結是應用Delphi 的bmp_rotate()函數來完成扭轉圖象的功效。並奇妙地挪用相干Windows API 函數來完成對文本的扭轉殊效。
完全的實例代碼以下:
unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,math, StdCtrls, ExtCtrls; type TForm1 = class(TForm) Edit1: TEdit; Image1: TImage; bmprotate: TButton; Label1: TLabel; Panel1: TPanel; Image2: TImage; Panel2: TPanel; Image3: TImage; Edit2: TEdit; RotatedText: TButton; Label2: TLabel; procedure bmprotateClick(Sender: TObject); procedure RotatedTextClick(Sender: TObject); procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } procedure bmp_rotate(src,dst:Tbitmap;angle:extended); Procedure DrawRotatedText(TheCanvas : TCanvas; TheAngle : Integer; TheText : String); end; var Form1: TForm1; implementation {$R *.DFM} procedure TForm1.bmp_rotate(src,dst:Tbitmap;angle:extended);//圖象扭轉 var c1x,c1y,c2x,c2y:integer; p1x,p1y,p2x,p2y:integer; radius,n:integer; alpha:extended; c0,c1,c2,c3:tcolor; begin angle := (angle / 180) * pi; //將文本框內的內容轉換角度 c1x := src.Width div 2; c1y := src.Height div 2; c2x := dst.Width div 2; c2y := dst.Height div 2; if c2x < c2y then n := c2y else n := c2x; dec (n,1); //使n 值削減1,n:=n-1 for p2x := 0 to n do begin for p2y := 0 to n do begin if p2x = 0 then alpha:= pi/2 else alpha := arctan2(p2y,p2x); radius := round(sqrt((p2x*p2x)+(p2y*p2y)));//設置扭轉時的半徑年夜小 p1x := round(radius * cos(angle+alpha)); //設置扭轉時的圓心橫坐標 p1y := round(radius * sin(angle+alpha)); //設置扭轉時的圓心縱坐標 c0 := src.Canvas.pixels[c1x+p1x,c1y+p1y];//調換圖象相干坐標處的像素 c1 := src.Canvas.pixels[c1x-p1x,c1y-p1y]; c2 := src.Canvas.pixels[c1x+p1y,c1y-p1x]; c3 := src.Canvas.pixels[c1x-p1y,c1y+p1x]; dst.Canvas.pixels[c2x+p2x,c2y+p2y]:=c0; //置換分歧地位的像素點 dst.Canvas.pixels[c2x-p2x,c2y-p2y]:=c1; dst.Canvas.pixels[c2x+p2y,c2y-p2x]:=c2; dst.Canvas.pixels[c2x-p2y,c2y+p2x]:=c3; end; application.processmessages //呼應其他的新聞要求 end; end; procedure TForm1.bmprotateClick(Sender: TObject); Var RAngle : Extended; begin RAngle := StrToFloat(Edit1.Text); //設置扭轉的角度 bmp_rotate(Image1.Picture.bitmap,Image2.Picture.bitmap, RAngle);//運轉扭轉函數,扭轉圖形 end; Procedure TForm1.DrawRotatedText(TheCanvas : TCanvas; TheAngle : Integer; TheText : String); var lf : TLogFont; tf : TFont; begin Image3.Canvas.refresh; with TheCanvas do begin Font.Name:='Arial'; Font.Size:=18; Brush.Style:= bsClear; tf:= TFont.Create; try tf.Assign(Font); GetObject(tf.Handle, Sizeof(lf), @lf); //將以後實例句柄賦給tf 這個Font 對象 lf.lfEscapement:=TheAngle*10; lf.lfOrientation := TheAngle * 10; //使輸出時的橫坐標線與程度線呈所指定的角度 tf.Handle := CreateFontIndirect(lf); //創立一個Font 詳細對象 Font.Assign(tf); //使這個對象應用到法式中 finally tf.Free; //釋放對象 end; TextOut(Image3.left, Image3.top+20 , TheText); //繪制文本到指定區域 end; end; procedure TForm1.RotatedTextClick(Sender: TObject); Var TheAngle : Integer; begin TheAngle := StrToInt(Edit2.Text); //將文本框中的文本轉換角度 DrawRotatedText(Image3.Canvas, TheAngle, 'Delphi圖形任務室'); //挪用扭轉文本函數 end; procedure TForm1.FormCreate(Sender: TObject); var tf : TFont; theText:string; begin theText:='Delphi圖形任務室'; //設置文本 with Image3.Canvas do begin Font.Name := 'Arial'; //設置字體 Font.Size := 18; //設置字體年夜小 Brush.Style := bsClear; //設置筆刷款式 tf:= TFont.Create; //創立一個Font 詳細對象 TextOut(Image3.left, Image3.top+20 , TheText); //繪制文本到指定區域 end; end; end.