噪声
提示:这里可以添加技术概要
核心源码
uses math;
procedure TForm1.Button1Click(Sender: TObject);
var
p: PByteArray;
x, y: Integer;
Bmp: TBitmap;
R, G, B: integer;
begin
Bmp := TBitmap.Create;
Bmp.Assign(Image1.Picture.Bitmap);
Bmp.PixelFormat := pf24Bit;
randomize;
for y := 0 to Bmp.Height - 1 do
begin
p := Bmp.scanline[y];
for x := 0 to Bmp.Width - 1 do
begin
R := P[3 * x + 2] + random(50) - 50 div 2;
G := p[3 * x + 1] + random(50) - 50 div 2;
B := p[3 * x] + random(50) - 50 div 2;
p[x * 3] := max(0, min(255, b));
p[x * 3 + 1] := max(0, min(255, g));
p[x * 3 + 2] := max(0, min(255, r));
end;
end;
Image2.Picture.Bitmap.Assign(Bmp);
Bmp.Free;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
p: PByteArray;
x, y: Integer;
Bmp: TBitmap;
R, G, B, a: integer;
begin
Bmp := TBitmap.Create;
Bmp.Assign(Image1.Picture.Bitmap);
Bmp.PixelFormat := pf24Bit;
randomize;
for y := 0 to Bmp.Height - 1 do
begin
p := Bmp.scanline[y];
for x := 0 to Bmp.Width - 1 do
begin
a := random(50) - 50 div 2;
R := P[3 * x + 2] + a;
G := p[3 * x + 1] + a;
B := p[3 * x] + a;
p[x * 3] := min(255, max(0, b));
p[x * 3 + 1] := min(255, max(0, g));
p[x * 3 + 2] := min(255, max(0, r));
end;
end;
Image3.Picture.Bitmap.Assign(Bmp);
Bmp.Free;
end;