这个算法大概就是您要求的效果了.
procedure CreateSponge(ABmp: TBitmap; ClipRgn: HRGN; Sponge: Integer);
var
i, j, x, y, r: Integer;
tempbmp : Tbitmap;
begin
if not assigned(abmp) then exit;
tempbmp := tbitmap.create;
tempbmp.assign(abmp);
for i := 0 to tempbmp.height - 1 do
for j := 0 to tempbmp.width - 1 do
begin
r := random(sponge);
x := triminteger( j + ( r - random(r * 2)), 0, tempbmp.width - 1);
y := triminteger(i + (r - random(r * 2)), 0, tempbmp.height - 1);
pbytearray(tempbmp.ScanLine)[j * 3] := pbytearray(tempbmp.scanline[y])[x * 3];
pbytearray(tempbmp.ScanLine)[j * 3+1] := pbytearray(tempbmp.scanline[y])[x * 3+1];
pbytearray(tempbmp.ScanLine)[j * 3+2] := pbytearray(tempbmp.scanline[y])[x * 3+2];
end;
selectcliprgn(abmp.canvas.handle, cliprgn);
bitblt(abmp.canvas.handle, 0, 0, abmp.width, abmp.height,
tempbmp.canvas.handle, 0, 0, SRCCOPY);
selectcliprgn(abmp.canvas.handle, 0);
tempbmp.free;
end;