scanline 方法的使用

来源:互联网 发布:vivo软件商店网页版 编辑:程序博客网 时间:2024/04/28 16:52

声明: property scanline[row: integer]: pointer  read  getscanline ;(只读)

//以下函数把位图变也灰度(可调节)
procedure graybitmap(abitmap: tbitmap; value: integer=0);
var
  pixel: prgbtriple;    //用来接收返回值
  w, h: integer;
  x, y: integer;
  avg: integer;
begin
  abitmap.pixelformat := pf24bit;
  w := abitmap.width;
  h := abitmap.height;
 
  for y := 0 to h - 1 do
  begin
    pixel := abitmap.scanline[y];
    for x := 0 to w - 1 do
    begin
      avg := ((pixel^.rgbtred + pixel^.rgbtgreen + pixel^.rgbtblue) div 3)+ value;
      if avg > 240 then avg := 240;
      pixel^.rgbtred := avg;
      pixel^.rgbtgreen := avg;
      pixel^.rgbtblue := avg;
      inc(pixel);
    end;
  end;
end;

附定义:  prgbtriple = ^trgbtriple;

trgbtriple = tagrgbtriple;
tagrgbtriple = packed record
    rgbtblue: byte;
    rgbtgreen: byte;
    rgbtred: byte;
end;

原创粉丝点击