Delphi實(shí)現(xiàn)圖像文本旋轉(zhuǎn)特效完整實(shí)例代碼
本文以實(shí)例講述了Delphi實(shí)現(xiàn)圖像文本旋轉(zhuǎn)特效的解決方法,在本程序中利用的控件主要是Panel 控件、Image 控件、Edit 控件、Label 控件和Button 控件。本程序的關(guān)鍵是利用Delphi 的bmp_rotate()函數(shù)來實(shí)現(xiàn)旋轉(zhuǎn)圖像的功能。并巧妙地調(diào)用相關(guān)Windows API 函數(shù)來實(shí)現(xiàn)對文本的旋轉(zhuǎn)特效。
完整的實(shí)例代碼如下:
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);//圖像旋轉(zhuǎn) 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; //將文本框內(nèi)的內(nèi)容轉(zhuǎn)換角度 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)));//設(shè)置旋轉(zhuǎn)時(shí)的半徑大小 p1x := round(radius * cos(angle+alpha)); //設(shè)置旋轉(zhuǎn)時(shí)的圓心橫坐標(biāo) p1y := round(radius * sin(angle+alpha)); //設(shè)置旋轉(zhuǎn)時(shí)的圓心縱坐標(biāo) c0 := src.Canvas.pixels[c1x+p1x,c1y+p1y];//替換圖像相關(guān)坐標(biāo)處的像素 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; //置換不同位置的像素點(diǎn) 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 //響應(yīng)其他的消息請求 end; end; procedure TForm1.bmprotateClick(Sender: TObject); Var RAngle : Extended; begin RAngle := StrToFloat(Edit1.Text); //設(shè)置旋轉(zhuǎn)的角度 bmp_rotate(Image1.Picture.bitmap,Image2.Picture.bitmap, RAngle);//運(yùn)行旋轉(zhuǎn)函數(shù),旋轉(zhuǎn)圖形 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); //將當(dāng)前實(shí)例句柄賦給tf 這個(gè)Font 對象 lf.lfEscapement:=TheAngle*10; lf.lfOrientation := TheAngle * 10; //使輸入時(shí)的橫坐標(biāo)線與水平線呈所指定的角度 tf.Handle := CreateFontIndirect(lf); //創(chuàng)建一個(gè)Font 具體對象 Font.Assign(tf); //使這個(gè)對象運(yùn)用到程序中 finally tf.Free; //釋放對象 end; TextOut(Image3.left, Image3.top+20 , TheText); //繪制文本到指定區(qū)域 end; end; procedure TForm1.RotatedTextClick(Sender: TObject); Var TheAngle : Integer; begin TheAngle := StrToInt(Edit2.Text); //將文本框中的文本轉(zhuǎn)換角度 DrawRotatedText(Image3.Canvas, TheAngle, 'Delphi圖形工作室'); //調(diào)用旋轉(zhuǎn)文本函數(shù) end; procedure TForm1.FormCreate(Sender: TObject); var tf : TFont; theText:string; begin theText:='Delphi圖形工作室'; //設(shè)置文本 with Image3.Canvas do begin Font.Name := 'Arial'; //設(shè)置字體 Font.Size := 18; //設(shè)置字體大小 Brush.Style := bsClear; //設(shè)置筆刷樣式 tf:= TFont.Create; //創(chuàng)建一個(gè)Font 具體對象 TextOut(Image3.left, Image3.top+20 , TheText); //繪制文本到指定區(qū)域 end; end; end.
上一篇:Delphi2007編譯的程序在Win7下圖標(biāo)模糊的解決辦法
欄 目:Delphi
本文標(biāo)題:Delphi實(shí)現(xiàn)圖像文本旋轉(zhuǎn)特效完整實(shí)例代碼
本文地址:http://mengdiqiu.com.cn/a1/Delphi/8619.html
您可能感興趣的文章
- 01-10在Delphi實(shí)現(xiàn)在數(shù)據(jù)庫中存取圖像的圖文演示無錯(cuò)
- 01-10delphi建立、讀取、存貯INI文件的方法《三》
- 01-10Delphi Command模式
- 01-10delphi 正弦曲線圖
- 01-10delphi建立、讀取、存貯INI文件的方法《二》
- 01-10插件管理框架 for Delphi(二)
- 01-10插件管理框架 for Delphi(一)
- 01-10Delphi中判斷文件是否為文本文件的函數(shù)
- 01-10delphi中一個(gè)值得大家來考慮的DLL問題
- 01-10初探Delphi中的插件編程


閱讀排行
本欄相關(guān)
- 01-10在Delphi實(shí)現(xiàn)在數(shù)據(jù)庫中存取圖像的圖
- 01-10delphi建立、讀取、存貯INI文件的方法
- 01-10delphi 正弦曲線圖
- 01-10Delphi Command模式
- 01-10delphi建立、讀取、存貯INI文件的方法
- 01-10插件管理框架 for Delphi(二)
- 01-10插件管理框架 for Delphi(一)
- 01-10Delphi中判斷文件是否為文本文件的函
- 01-10delphi中一個(gè)值得大家來考慮的DLL問題
- 01-10初探Delphi中的插件編程
隨機(jī)閱讀
- 01-10使用C語言求解撲克牌的順子及n個(gè)骰子
- 04-02jquery與jsp,用jquery
- 01-11Mac OSX 打開原生自帶讀寫NTFS功能(圖文
- 08-05織夢dedecms什么時(shí)候用欄目交叉功能?
- 01-10SublimeText編譯C開發(fā)環(huán)境設(shè)置
- 01-11ajax實(shí)現(xiàn)頁面的局部加載
- 01-10delphi制作wav文件的方法
- 08-05dedecms(織夢)副欄目數(shù)量限制代碼修改
- 08-05DEDE織夢data目錄下的sessions文件夾有什
- 01-10C#中split用法實(shí)例總結(jié)