谢谢zw84611
我用SOCKET写了一便
SERVER:
---------------------
procedure TForm1.serverClientRead(Sender: TObject;
Socket: TCustomWinSocket);
var strsize:integer;
buf
char;
x,y:integer;
l1, l2,l3: PByteArray;
Bmp1, Bmp2, Bmp3: TBitmap;
begin
strsize:=socket.ReceiveLength ;
if strsize=3 then
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];
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;
socket.SendBuf(l3,sizeof(l3));
end;
Bmp1.Free;
Bmp2.Free;
bmp3.Free ;
end;
-----------------------------------
CLIENT:
-----------------------------------
procedure TForm1.ClientRead(Sender: TObject; Socket: TCustomWinSocket);
var l1,l2
ByteArray;
x,y,p:integer;
strsize:integer;
s1,s2:string;
bmp1:Tbitmap;
b:boolean;
begin
strsize:=socket.ReceiveLength ;
bmp1:=Tbitmap.Create ;
Bmp1.Assign(Image1.Picture.Bitmap);
if strsize>0 then
socket.ReceiveBuf(l1,strsize);
for y := 0 to Image1.Height-1 do
begin
l2 := Bmp1.ScanLine[y];
for x := 0 to sizeof(l1)-1 do
begin
if l1[x]<>l2[x] then (**********************)
begin
CopyMemory(l2,l1,sizeof(l1));
end;
end;
image1.Picture.Bitmap.Assign(bmp1);
Bmp1.Free;
end;
end;
为什么在CLIENT执行到 if l1[x]<>l2[x] then时出现了错误?
那么正确的写法是什么?