如何将一张彩色图片转换成黑白图片

huiwww 2006-12-07 01:00:09
如何将一张彩色图片转换成黑白图片
...全文
301 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
Comer 2006-12-07
  • 打赏
  • 举报
回复
mark

学习
阿发伯 2006-12-07
  • 打赏
  • 举报
回复
或者:

procedure TForm1.Button3Click(Sender: TObject);
var
P: PByteArray;
x, y: Integer;
Gray: 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[3*x+2] * 0.3 + P[3*x+1] * 0.59 + P[3*x] * 0.11);
P[3*x+2] := Byte(Gray);
P[3*x+1] := Byte(Gray);
P[3*x] := Byte(Gray);
end;
end;
Canvas.Draw(0, 0, Bmp);
Bmp.Free;
end;
阿发伯 2006-12-07
  • 打赏
  • 举报
回复
或者:

procedure TForm1.Button3Click(Sender: TObject);
var
P: PByteArray;
x, y: Integer;
Gray: 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 := Max(P[3*x+2], P[3*x+1]);
Gray := Max(Gray, P[3*x]);
P[3*x+2] := Byte(Gray);
P[3*x+1] := Byte(Gray);
P[3*x] := Byte(Gray);
end;
end;
Canvas.Draw(0, 0, Bmp);
Bmp.Free;
end;
阿发伯 2006-12-07
  • 打赏
  • 举报
回复

procedure TForm1.Button3Click(Sender: TObject);
var
P: PByteArray;
x, y: Integer;
Gray: 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 := (P[3*x+2] + P[3*x+1] + P[3*x]) div 3;
P[3*x+2] := Byte(Gray);
P[3*x+1] := Byte(Gray);
P[3*x] := Byte(Gray);
end;
end;
Canvas.Draw(0, 0, Bmp);
Bmp.Free;
end;

1,183

社区成员

发帖
与我相关
我的任务
社区描述
Delphi GAME,图形处理/多媒体
社区管理员
  • GAME,图形处理/多媒体社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧