程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> Delphi圖象效果處理[通道和水彩、失真、明暗效果的實現代碼]

Delphi圖象效果處理[通道和水彩、失真、明暗效果的實現代碼]

編輯:Delphi

Delphi圖象處理效果集,主要是提取通道圖像,比如變換紅原色通道、變換綠原色和藍色通道,還有一些水彩效果、失真效果、明暗效果等,代碼中關鍵部分已標注了中文說明,對學習圖像效果的處理有幫助。

01 unit Unit1; 02 interface 03 uses 04   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 05   Dialogs, StdCtrls, ExtCtrls, jpeg, ComCtrls; 06 type 07   TForm1 = class(TForm) 08     Image1: TImage; 09     Image2: TImage; 10     Button1: TButton; 11     ListBox1: TListBox; 12     Label1: TLabel; 13     Button2: TButton; 14     SaveDialog1: TSaveDialog; 15     procedure Button1Click(Sender: TObject); 16     procedure Button2Click(Sender: TObject); 17   private 18     { Private declarations } 19   public 20     { Public declarations } 21   end; 22 var 23   Form1: TForm1; 24 implementation 25 {$R *.dfm} 26 procedure TForm1.Button1Click(Sender: TObject); 27 Var i,j,newR,newG,newB:Integer; 28 begin 29  For i:=0 To Image1.Width Do 30   For j:=0 To Image1.Height Do 31 Begin 32    //新的紅原色 33 newR:=Round(GetRValue(Image1.Canvas.Pixels[i-1,j-1])+GetRValue(Image1.Canvas.Pixels[i-1,j])+GetRValue(Image1.Canvas.Pixels[i-1,j+1]) 34        +GetRValue(Image1.Canvas.Pixels[i,j-1])+GetRValue(Image1.Canvas.Pixels[i,j])+GetRValue(Image1.Canvas.Pixels[i,j+1])+ 35        GetRValue(Image1.Canvas.Pixels[i+1,j-1])+GetRValue(Image1.Canvas.Pixels[i+1,j])+GetRValue(Image1.Canvas.Pixels[i+1,j+1])/9); 36   //新的綠原色 37 newG:=Round(GetGValue(Image1.Canvas.Pixels[i-1,j-1])+GetGValue(Image1.Canvas.Pixels[i-1,j])+GetGValue(Image1.Canvas.Pixels[i-1,j+1]) 38        +GetGValue(Image1.Canvas.Pixels[i,j-1])+GetGValue(Image1.Canvas.Pixels[i,j])+GetGValue(Image1.Canvas.Pixels[i,j+1])+ 39        GetGValue(Image1.Canvas.Pixels[i+1,j-1])+GetGValue(Image1.Canvas.Pixels[i+1,j])+GetGValue(Image1.Canvas.Pixels[i+1,j+1])/9); 40   //新的藍原色 41 newB:=Round(GetBValue(Image1.Canvas.Pixels[i-1,j-1])+GetBValue(Image1.Canvas.Pixels[i-1,j])+GetBValue(Image1.Canvas.Pixels[i-1,j+1]) 42        +GetBValue(Image1.Canvas.Pixels[i,j-1])+GetBValue(Image1.Canvas.Pixels[i,j])+GetBValue(Image1.Canvas.Pixels[i,j+1])+ 43        GetBValue(Image1.Canvas.Pixels[i+1,j-1])+GetBValue(Image1.Canvas.Pixels[i+1,j])+GetBValue(Image1.Canvas.Pixels[i+1,j+1])/9); 44 Case ListBox1.ItemIndex Of 45 0:Image2.Canvas.Pixels[i,j]:=RGB( 46       255,                                        //變換紅原色通道 47       GetGValue(Image1.Canvas.Pixels[i,j]), 48       GetBValue(Image1.Canvas.Pixels[i,j])); 49 1:Image2.Canvas.Pixels[i,j]:=RGB( 50       GetRValue(Image1.Canvas.Pixels[i,j]), 51       255,                                        //變換綠原色通道 52       GetBValue(Image1.Canvas.Pixels[i,j])); 53 2:Image2.Canvas.Pixels[i,j]:=RGB( 54       GetRValue(Image1.Canvas.Pixels[i,j]), 55       GetGValue(Image1.Canvas.Pixels[i,j]), 56       255);                                       //變換藍原色通道 57 3:Image2.Canvas.Pixels[i,j]:=RGB(                 //水彩效果 58         GetRValue(newR),                   59         GetGValue(Image1.Canvas.Pixels[i,j]), 60         GetBValue(Image1.Canvas.Pixels[i,j])); 61 4:Image2.Canvas.Pixels[i,j]:=RGB(                 //紫色通道 62         GetRValue(Image1.Canvas.Pixels[i,j]), 63         GetGValue(newG), 64         GetBValue(Image1.Canvas.Pixels[i,j])); 65 5:Image2.Canvas.Pixels[i,j]:=RGB(                 //黃色通道 66         GetRValue(Image1.Canvas.Pixels[i,j]), 67         GetGValue(Image1.Canvas.Pixels[i,j]), 68         GetBValue(newB)); 69 6:Image2.Canvas.Pixels[i,j]:=RGB(                //失真效果 70         GetRValue(newR), 71         GetGValue(newG), 72         GetBValue(newB)); 73 7:Image2.Canvas.Pixels[i,j]:=RGB(               //柔化效果 74       GetRValue(Image1.Canvas.Pixels[i-2,j-2]), 75       GetGValue(Image1.Canvas.Pixels[i,j]), 76       GetBValue(Image1.Canvas.Pixels[i+2,j+2])); 77 8:Image2.Canvas.Pixels[i,j]:=RGB(              //明暗效果 78       Round(GetGValue(Image1.Canvas.Pixels[i,j])/4),                                              //變換紅原色通道 79       Round(GetGValue(Image1.Canvas.Pixels[i,j])/4), 80       Round(GetBValue(Image1.Canvas.Pixels[i,j])/4)); 81   end; 82   end; 83 End; 84 procedure TForm1.Button2Click(Sender: TObject); 85 begin 86 If SaveDialog1.Execute Then 87  Image2.Picture.SaveToFile(SaveDialog1.FileName);   //保存效果圖 88 end; 89 end.

 程序運行效果圖:

圖像處理和通道處理delphi代碼

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