Przedstawiony poniżej kod umożliwia stworzenie efektu rozmycia (blur) na dowolnym obrazie BMP. Format pikseli musi być 24 lub 32 bitowy.
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 |
procedure Rozmycie( Can: TCanvas; X, Y, Szerokosc, Wysokosc : Integer); var cx, cy: Smallint; r, g, b: Byte; Row1: pRGBTripleArray; Row2: pRGBTripleArray; Row3: pRGBTripleArray; TEMP: TBitmap; CurRect: TRect; begin TEMP := TBitmap.Create; try with TEMP do begin Width := Szerokosc; Height := Wysokosc; CurRect := Rect(0, 0, Szerokosc, Wysokosc); PixelFormat := pf24Bit; Canvas.CopyRect(CurRect, Can, Rect(X,Y,Szerokosc, Wysokosc)); with Canvas do begin for cy := 1 to (Height - 2) do begin Row1 := ScanLine[cy - 1]; Row2 := ScanLine[cy]; Row3 := ScanLine[cy + 1]; for cx := 1 to (Width - 2) do begin r := (Row1[cx - 1].rgbtRed+Row1[cx].rgbtRed+ Row1[cx + 1].rgbtRed+ Row2[cx - 1].rgbtRed+ Row2[cx + 1].rgbtRed+ Row2[cx - 1].rgbtRed+ Row3[cx].rgbtRed+ Row3[cx + 1].rgbtRed+ Row3[cx].rgbtRed) div 9; g := (Row1[cx - 1].rgbtGreen+ Row1[cx].rgbtGreen+ Row1[cx + 1].rgbtGreen+ Row2[cx - 1].rgbtGreen+ Row2[cx + 1].rgbtGreen+ Row2[cx - 1].rgbtGreen+ Row3[cx].rgbtGreen+ Row3[cx + 1].rgbtGreen+ Row3[cx].rgbtGreen) div 9; b := (Row1[cx - 1].rgbtBlue+ Row1[cx].rgbtBlue+ Row1[cx + 1].rgbtBlue+ Row2[cx - 1].rgbtBlue+ Row2[cx + 1].rgbtBlue+ Row2[cx - 1].rgbtBlue+ Row3[cx].rgbtBlue+ Row3[cx + 1].rgbtBlue+ Row3[cx].rgbtBlue) div 9; Row2[cx].rgbtBlue := b; Row2[cx].rgbtGreen := g; Row2[cx].rgbtRed := r; end; end; end; Can.CopyRect(Rect(X,Y,Szerokosc,Wysokosc), Canvas, CurRect); end; finally TEMP.Free; end; end; |
Teraz wystarczy wywołać procedurę :
1 |
Rozmycie(image1.picture.Bitmap.Canvas,-10,-10,650,490); |
Autor: Nakiel