本文整理自网络,侵删。
效果图:
var
p: PByteArray; Gray, x, y: Integer; Bmp:TBitmap;
beginBmp:=TBitmap.Create;Bmp.Assign(Image1.Picture.Graphic); //设置为24位真彩色 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 //一个象素点三个字节 Gray := Round(p[x * 3 + 2] * 0.3 + p[x * 3 + 1] * 0.59 + p[x * 3] * 0.11); if gray > 128 then //全局阀值128 begin 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.Assign(Bmp);
相关阅读 >>
Delphi stringtowidestring widestringtostring
Delphi版的隐藏模块单元 hidemoduleunit.pas
Delphi 2009 之 tstringbuilder 类[5]: chars[] 属性与 copyto 方法
Delphi 解决idtcpclient和idtcpserver通信中文乱码问题
更多相关阅读请进入《Delphi》频道 >>