1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131:
| unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls,JPEG, ComCtrls;
type MyThread=class(TThread) procedure Execute;override; private procedure DoBlur; public end;
type TForm1 = class(TForm) Image1: TImage; Button1: TButton; Button2: TButton; Button3: TButton; OpenDialog1: TOpenDialog; SaveDialog1: TSaveDialog; ProgressBar1: TProgressBar; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure Button3Click(Sender: TObject); private t:MyThread; function Blur(bmp:TBitmap):TBitmap; function RGBtoColor(r,g,b:Byte):TColor; procedure GetRGB(var R:Byte;var B:Byte;var G:Byte;cl:TColor); public end;
var Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject); begin if OpenDialog1.Execute then Image1.Picture.LoadFromFile(OpenDialog1.FileName); end;
procedure TForm1.Button2Click(Sender: TObject); begin if SaveDialog1.Execute then Image1.Picture.SaveToFile(SaveDialog1.FileName); end;
function TForm1.Blur(bmp:TBitmap):TBitmap; var i,j,x,y:Integer; R,G,B:Byte; rges,gges,bges:Integer; newbmp:TBitmap; proz,anz,ges:Real; begin proz:=0; newbmp:=TBitmap.Create; newbmp.Height:=bmp.Height-10; newbmp.Width:=bmp.Width-10; ges:=newbmp.Height*newbmp.Width; anz:=0; for x:=5 to bmp.Width-5 do for y:=5 to bmp.Height-5 do begin rges:=0; bges:=0; gges:=0; for i:=x-5 to x+5 do for j:=y-5 to y+5 do begin GetRGB(R,G,B,bmp.Canvas.Pixels[i,j]); rges:=rges+R; bges:=bges+B; gges:=gges+G; end; rges:=TRUNC(rges/100); bges:=TRUNC(bges/100); gges:=TRUNC(gges/100); newbmp.Canvas.Pixels[x-5,y-5]:=RGBtoColor(rges,gges,bges); anz:=anz+1; proz:=anz/ges; ProgressBar1.Position:=Round(100*proz); end; ProgressBar1.Position:=0; newbmp.Transparent:=true; result:=newbmp; end;
procedure TForm1.GetRGB(var R:Byte;var B:Byte;var G:Byte;cl:TColor); begin R := cl and $FF; G := (cl shr 8) and $FF; B := (cl shr 16) and $FF; end;
procedure MyThread.Execute; begin Synchronize(DoBlur); end;
procedure TForm1.FormCreate(Sender: TObject); begin t:=MyThread.Create(true); end;
procedure TForm1.Button3Click(Sender: TObject); begin t.Execute; end;
procedure MyThread.DoBlur; begin Form1.Image1.Picture.Bitmap:=Form1.Blur(Form1.Image1.Picture.Bitmap); end;
function TForm1.RGBtoColor(r,g,b:Byte):TColor; begin result:=$00000000 or r; result:=result or (g shl 8); result:=result or (b shl 16); end;
end. |