Wolfgang Chien's Homepage | Delphi學習筆記 - 問答篇 |
如果要在Delphi下秀二張圖, 而第一張要蓋在第二 張 上面且第一張的背景色不能蓋上去..就好像第一張跑進第二張一樣..這在程式上應如何寫作? 或是用好用的component?
以前看過一個作動畫處理的例子 ---- 忘了出處了, 否則直接告訴您出處應該比較好.
以下有一個例子, 花了好久才記起來怎麼作的:
方法大綱
以一張黑白的遮罩圖片, 將前景圖片的主體部分從背景圖片中去掉, 然後再置入前景圖片
![]() |
1. 名詞約定
|
![]() |
2. 製作圖片:
|
![]() |
3. File | New Project |
![]() |
4. 在 Form1 中放 TPaintBox 與 TButton 各一, 將 PaintBox 的 Name 屬性改成 WorkSpace |
![]() |
5. Button1 的 OnClick 事件:
procedure TForm1.Button1Click(Sender: TObject); var BackGround, ForeGround, MaskBmp: TBitMap; iWidth, iHeight: integer; sAppPath: string; begin (* 程式啟動作業 *) sAppPath := ExtractFilePath(Application.ExeName); (* 置入背景圖片 *) BackGround := TBitMap.Create; with BackGround do begin LoadFromFile(sAppPath + 'clouds.bmp'); iWidth := Width; iHeight := Height; end; with WorkSpace.Canvas do begin CopyMode := cmSrcCopy; StretchDraw(Rect(0, 0, iWidth, iHeight), Background); end; ShowMessage('置入背景圖片'); (* 以遮罩圖片清出前景圖片的主體部分 *) MaskBmp := TBitMap.Create; with MaskBmp do begin LoadFromFile(sAppPath + 'Maskbmp.bmp'); iWidth := Width; iHeight := Height; end; with WorkSpace.Canvas do begin CopyMode := cmSrcAnd; CopyRect(Rect(0, 0, iWidth, iHeight), MaskBmp.Canvas, Rect(0, 0, MaskBmp.Width, MaskBmp.Height)); end; ShowMessage('以遮罩圖片清出前景圖片的主體部分'); (* 置入前景圖片 *) ForeGround := TBitMap.Create; with ForeGround do begin LoadFromFile(sAppPath + 'forebmp.bmp'); iWidth := Width; iHeight := Height; end; with WorkSpace.Canvas do begin CopyMode := cmSrcPaint; CopyRect(Rect(0, 0, iWidth, iHeight), ForeGround.Canvas, Rect(0, 0, ForeGround.Width, ForeGround.Height)); end; ShowMessage('置入前景圖片'); BackGround.Free; ForeGround.Free; MaskBmp.Free; end; |
![]() |
6. 執行看看吧! |
後記: 您可以在學習筆記(創作篇)中找到這個貼圖的範例程式
首頁 | 學習筆記 | 主題公園 | 軟體下載 | 關於本站 | 討論信群 | 相約下次 |