图片合并问题(200分)

  • 主题发起人 主题发起人 goeasy
  • 开始时间 开始时间
谁有ScanLine扫描图象的代码,请公布一份好么?现在全文检索不好用。谢谢,收到后散分!!!!
 
你的email,发一个简单的例子给你看看?
 
方法一:
//getpixel
procedure TForm1.Button1Click(Sender: TObject);
var
y,x,r1,r2: integer;
Bitmap1, Bitmap2: TBitmap;
begin

// just for JPG images
Bitmap1 := TBitmap.Create;
Bitmap2 := TBitmap.Create;
Clipboard.Assign(Image1.Picture);
Bitmap1.LoadFromClipBoardFormat(cf_BitMap,ClipBoard.GetAsHandle(cf_Bitmap),0);
Clipboard.Assign(Image2.Picture);
Bitmap2.LoadFromClipBoardFormat(cf_BitMap,ClipBoard.GetAsHandle(cf_Bitmap),0);

for y:=0 to image2.Height do
begin
x:=0;
repeat
x:=x+1 ;
r1:= getpixel(Bitmap1.Canvas.Handle,x,y);
r2:= getpixel(Bitmap2.Canvas.Handle,x,y);
if r1 <> r2 then
memo1.Lines.Add(inttostr(x)+','+inttostr(y));
until x>image2.Width ;
end;
memo1.Lines.Add('end');

Bitmap1.Free;
Bitmap2.Free;

end;

方法二:
//TBitmap.ScanLine得到位图某行的指针.
procedure TForm1.Button2Click(Sender: TObject);
var
l1, l2, l3: PByteArray;
y, x: integer;
//b: boolean;
Bmp1, Bmp2, Bmp3: TBitmap;
begin

Bmp1 :=TBitmap.Create;
Bmp1.Assign(Image1.Picture.Bitmap);
Bmp2 :=TBitmap.Create;
Bmp2.Assign(Image2.Picture.Bitmap);
Bmp3 :=TBitmap.Create;
Bmp3.Width := Bmp1.Width;
Bmp3.Height := Bmp1.Height;

Bmp1.pixelformat := pf32bit;
Bmp2.pixelformat := pf32bit;
Bmp3.pixelformat := pf32bit;

for y := 0 to Image1.Picture.Height-1 do
begin
l1 := Bmp1.ScanLine[y];
l2 := Bmp2.ScanLine[y];
l3 := Bmp3.ScanLine[y];
//b := false;
for x := 0 to Image2.Picture.Width-1 do
begin
if l1[x]<>l2[x] then
begin
l3[x] := l1[x] and l2[x];
end
else l3[x] := l1[x];
end;
end;

Image2.Picture.Bitmap.Assign(Bmp3);
Bmp1.Free;
Bmp2.Free;
Bmp3.Free;

end;
 
多人接受答案了。
 
后退
顶部