全部博文(788)
分类:
2008-08-31 09:52:09
procedure TForm1.Button3Click(Sender: TObject);
var
P: PByteArray;
x, y: Integer;
Gray: Integer;
Bmp: TBitmap;
begin
Bmp := TBitmap.Create;
Bmp.Assign(Image1.Picture.Bitmap);
Bmp.PixelFormat := pf24bit;
for y := 0 to Bmp.Height - 1 do
begin
P := Bmp.ScanLine[y];
for x := 0 to Bmp.Width - 1 do
begin
Gray := (P[3*x+2] + P[3*x+1] + P[3*x]) div 3;
P[3*x+2] := Byte(Gray);
P[3*x+1] := Byte(Gray);
P[3*x] := Byte(Gray);
end;
end;
Canvas.Draw(0, 0, Bmp);
Bmp.Free;
end;
或者:
procedure TForm1.Button3Click(Sender: TObject);
var
P: PByteArray;
x, y: Integer;
Gray: Integer;
Bmp: TBitmap;
begin
Bmp := TBitmap.Create;
Bmp.Assign(Image1.Picture.Bitmap);
Bmp.PixelFormat := pf24bit;
for y := 0 to Bmp.Height - 1 do
begin
P := Bmp.ScanLine[y];
for x := 0 to Bmp.Width - 1 do
begin
Gray := Max(P[3*x+2], P[3*x+1]);
Gray := Max(Gray, P[3*x]);
P[3*x+2] := Byte(Gray);
P[3*x+1] := Byte(Gray);
P[3*x] := Byte(Gray);
end;
end;
Canvas.Draw(0, 0, Bmp);
Bmp.Free;
end;
或者:
procedure TForm1.Button3Click(Sender: TObject);
var
P: PByteArray;
x, y: Integer;
Gray: Integer;
Bmp: TBitmap;
begin
Bmp := TBitmap.Create;
Bmp.Assign(Image1.Picture.Bitmap);
Bmp.PixelFormat := pf24bit;
for y := 0 to Bmp.Height - 1 do
begin
P := Bmp.ScanLine[y];
for x := 0 to Bmp.Width - 1 do
begin
Gray := Round(P[3*x+2] * 0.3 + P[3*x+1] * 0.59 + P[3*x] * 0.11);
P[3*x+2] := Byte(Gray);
P[3*x+1] := Byte(Gray);
P[3*x] := Byte(Gray);
end;
end;
Canvas.Draw(0, 0, Bmp);
Bmp.Free;
end;
mark
学习