请问如何把一个24位Bitmap转成8位灰度图,请提供算法,最好有例子(200分)

  • 主题发起人 主题发起人 msc
  • 开始时间 开始时间
M

msc

Unregistered / Unconfirmed
GUEST, unregistred user!
请问如何把一个24位Bitmap转成8位灰度图
 
灰度 := R*0.3+G*0.59+B*0.11
 
//灰度级处理
procedure Gray(bmp: TBitmap);
var
p: PByteArray;
w: Integer;
i, j: Integer;
begin
bmp.pixelformat := pf24bit;
for i := 0 to bmp.height - 1 do
begin
p := bmp.scanline;
j := 0;
while j < (bmp.width-1) * 3 do
begin
w :=(p[j] * 28 + p[j+1] * 151 + p[j+2]*77);
w := w shr 8;
p[j] := byte(w);
p[j+1] := byte(w);
p[j+2] := byte(w);
inc(j, 3)
end;
end;
end;

procedure TForm1.g1Click(Sender: TObject);
var
Bmp : TBitMap;
begin
PaintBox1.Repaint;
Bmp := TBitMap.Create;
Bmp.Assign(Image1.Picture.Bitmap);
//Convert(Image1.Picture.Bitmap,Bmp);
Gray(bmp);
PaintBox1.Canvas.Draw(0,0,Bmp);
Bmp.Free;
end;
 
后退
顶部