I
inf
Unregistered / Unconfirmed
GUEST, unregistred user!
我在编写图像处理程序的时候,遇到调整图像的伪彩,达到显示不同色彩的效果,我这里有一段代码,但是不知道如何用程序控制伪彩的调整,或者,哪位大虾有类似功能的代码可以让小弟学习一下也可。
procedure TForm1.N22Click(Sender: TObject);
var
p: PByteArray;
x, y: Integer;
Bmp: TBitmap;
Gray: byte;
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[x * 3 + 2] * 0.3 + p[x * 3 + 1] * 0.59 + p[x
* 3]
* 0.11);
if gray < 63 then
begin
p[x * 3 + 2] := 0;
p[x * 3 + 1] := 254 - 4 * gray;
p[x * 3] := 255;
end;
if (64 <= gray) and (gray < 127) then
begin
p[x * 3 + 2] := 0;
p[x * 3 + 1] := 4 * gray - 254;
p[x * 3] := 510 - 4 * gray;
end;
if (128 <= gray) and (gray < 191) then
begin
p[x * 3 + 2] := 4 * gray - 510;
p[x * 3 + 1] := 255;
p[x * 3] := 0;
end;
if (192 <= gray) then
begin
p[x * 3 + 2] := 255;
p[x * 3 + 1] := 1022 - 4 * gray;
p[x * 3] := 0;
end;
end;
end;
Image1.Picture.Bitmap.Assign(Bmp);
end;
希望各位高手给予帮助,谢谢!
procedure TForm1.N22Click(Sender: TObject);
var
p: PByteArray;
x, y: Integer;
Bmp: TBitmap;
Gray: byte;
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[x * 3 + 2] * 0.3 + p[x * 3 + 1] * 0.59 + p[x
* 3]
* 0.11);
if gray < 63 then
begin
p[x * 3 + 2] := 0;
p[x * 3 + 1] := 254 - 4 * gray;
p[x * 3] := 255;
end;
if (64 <= gray) and (gray < 127) then
begin
p[x * 3 + 2] := 0;
p[x * 3 + 1] := 4 * gray - 254;
p[x * 3] := 510 - 4 * gray;
end;
if (128 <= gray) and (gray < 191) then
begin
p[x * 3 + 2] := 4 * gray - 510;
p[x * 3 + 1] := 255;
p[x * 3] := 0;
end;
if (192 <= gray) then
begin
p[x * 3 + 2] := 255;
p[x * 3 + 1] := 1022 - 4 * gray;
p[x * 3] := 0;
end;
end;
end;
Image1.Picture.Bitmap.Assign(Bmp);
end;
希望各位高手给予帮助,谢谢!