漸層色的作法

有關Delphi 的語法, 程式, 等
回覆文章
頭像
tim
文章: 1380
註冊時間: 2008年 11月 26日, 00:49

漸層色的作法

文章 tim »

本範例使用了 TImage 的 Canvas 來進行漸層色的填充
放一個 TImage 在 TPanel 上, 並設定 alClient 屬性!

代碼: 選擇全部

     
    procedure Tform1.formCreate(Sender: TObject); 
    var 
      cStart, cEnd, cTemp, cSR, cSG, cSB, cER, cEG, cEB: TColor; 
      i, ir, ig, ib: integer; 
      width: double; 
    begin 
      //Image1.Canvas.FillRect(Rect(0,0,Image1.Width,Image1.Height)); 
      cStart := clRed; 
      cEnd := clBlue; 
      cSR := cStart and $000000FF; 
      cSG := cStart and $0000FF00 shr 8; 
      cSB := cStart and $00FF0000 shr 16; 
      cER := cEnd and $000000FF; 
      cEG := cEnd and $0000FF00 shr 8; 
      cEB := cEnd and $00FF0000 shr 16; 
      ir := (cER - cSR) div 100; 
      ig := (cEG - cSG) div 100; 
      ib := (cEB - cSB) div 100; 
      width := Image1.Width / 100; 
      for i := 0 to 99 do 
      begin 
        Image1.Canvas.Brush.Color := (cSR + ir * i) or ((cSG + ig * i) shl <img src=../emoticons/smile.gif> or ((cSB + ib * i) shl 16); 
        Image1.Canvas.FillRect(Rect(Round(i*width),0,Round((i+1)*width), Image1.Height)); 
      end; 
     
    end; 


原始參考資料:
http://delphi.ktop.com.tw/topic.asp?topic_id=39056
多多留言, 整理文章, 把經驗累積下來.....
回覆文章