真彩图片转为灰度图片.(100分)

  • 主题发起人 eastweast
  • 开始时间
E

eastweast

Unregistered / Unconfirmed
GUEST, unregistred user!
如何才能够将一幅真彩色的图像转换为256的灰度图像?
 
var
p :pByteArray;
Gray,x,y :Integer;
Bmp :TBitmap;
begin
Bmp :=TBitmap.Create;
Bmp.Assign(Image.Picture.Bitmap);
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;
Image.Picture.Bitmap.Assign(Bmp);
Bmp.Free;
end;
 
亮度(0..255)=(B*28+G*151+R*77)div 256;

w := (p[j] * 28 + p[j + 1] * 151 + p[j + 2] * 77);
 
接受答案。
 
接受答案。
 
顶部