像素分解(200分)

  • 主题发起人 主题发起人 liubin11
  • 开始时间 开始时间
L

liubin11

Unregistered / Unconfirmed
GUEST, unregistred user!
图片处理:将真彩色图像分解为表现红、蓝、绿三色的灰度图像并取逆,存成三个位图
如何处理?急!!
 
看看有没有用
Image1.Picture.Bitmap.Canvas.Pixels[n, m]

RGB(GetBValue(c), GetGValue(c), GetRValue(c));
 
如何读取真色彩图像?如何存成三个位图?
 
procedure TForm1.Button1Click(Sender: TObject);
var
x, y : Integer;
Bitmap : TBitmap;
begin
Bitmap := TBitmap.Create;
Bitmap.LoadFromFile('C:/WINDOWS/Carved Stone.bmp');
with Bitmap do
for x := 0 to Width do
for y := 0 to Height do
begin
Image1.Canvas.Pixels[x, y] :=
RGB(GetGValue(Canvas.Pixels[x, y]), 0, 0);
end;
Bitmap.Free;
end;
 
// 装载图像
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
if OpenPictureDialog1.Execute then
Image1.Picture.LoadFromFile(OpenPictureDialog1.FileName);
end;
// 将Image1中的内容分解成R,B,G三色,并保存到Res0.bmp, Res1.bmp, Res2.bmp
procedure TForm1.Button1Click(Sender: TObject);
var
bitmap: TBitmap;
fPath: string;
c: TColor;
i, x, y: integer;
begin
// 取原路径
fPath := ExtractFilePath(OpenPictureDialog1.FileName);
// 创建缓冲区
bitmap := TBitmap.Create;
try
with bitmap do
begin
Width := Image1.Picture.Bitmap.Width; // 缓冲区尺寸
Height := Image1.Picture.Bitmap.Height;

for i := 0 to 2 do
begin
for y := 0 to Height - 1 do // 行扫描
for x := 0 to Width - 1 do // 列扫描
begin
// 取原图像颜色
c := Image1.Picture.Bitmap.Canvas.Pixels[x,y];
// 取颜色,并取反
case i of
0: c := RGB(255-GetRValue(c), 0, 0);
1: c := RGB(0, 255-GetGValue(c), 0);
2: c := RGB(0, 0, 255-GetBValue(c));
end;
Canvas.Pixels[x,y] := c; // 写目标
end;
// 保存
SaveToFile(fPath + 'Res'+ IntToStr(i) +'.BMP');
end;
end;
finally
bitmap.Free;
end;
end;
 
楼上的代码已经很经典了,只有学习的份了
 
多人接受答案了。
 

Similar threads

D
回复
0
查看
793
DelphiTeacher的专栏
D
D
回复
0
查看
828
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
660
DelphiTeacher的专栏
D
后退
顶部