procedure TForm1.Button1Click(Sender: TObject);
var
p ByteArray;
Gray,x,y :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[x*3+2]*0.3+p[x*3+1]*0.59+p[x*3]*0.11);
p[x*3]:=Gray;
p[x*3+1]:=Gray;
p[x*3+2]:=Gray;
end;
end;
Image1.Picture.Bitmap.Assign(Bmp);
Bmp.Free;
end;
取一个阀值啊!
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[x * 3 + 2] * 0.3 + p[x * 3 + 1] * 0.59 + p[x * 3]
* 0.11);
if gray > 128 then //È¡¸ö·§Öµ
begin
// if a<>0 then
p[x * 3] := 255;
p[x * 3 + 1] := 255;
p[x * 3 + 2] := 255;
end
else
begin
p[x * 3] := 0;
p[x * 3 + 1] := 0;
p[x * 3 + 2] := 0;
end;
end;
end;
Image1.Picture.Bitmap.Assign(Bmp);