SCANLINE怎么用?(50分)

L

logpie

Unregistered / Unconfirmed
GUEST, unregistred user!
GETPIXEL太慢了,我想该用SCANLINE,请问
用CSANLINE比较2图,一行一行的扫描,怎么比较一行中是否有差别?
又怎样再把这行重画到第一副图的相应行上?谢谢
 
//TBitmap.ScanLine得到位图某行的指针.
procedure TForm1.Button2Click(Sender: TObject);
var
l1, l2: PByteArray;
y, x: integer;
b: boolean;
Bmp1, Bmp2: TBitmap;
begin

//Image1.Picture.Bitmap.pixelformat := pf8bit;
//Image2.Picture.Bitmap.pixelformat := pf8bit;

Bmp1 :=TBitmap.Create;
Bmp1.Assign(Image1.Picture.Bitmap);
Bmp2 :=TBitmap.Create;
Bmp2.Assign(Image1.Picture.Bitmap);

for y := 0 to Image1.Height-1 do
begin
l1 := Bmp1.ScanLine[y];
l2 := Bmp2.ScanLine[y];
b := false;
for x := 0 to sizeof(l1)-1 do
begin
if l1[x]<>l2[x] then
begin
b := true;
break;
end;
end;
if b then CopyMemory(l2,l1,sizeof(l1));
end;

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

end;

但下面的方法可能更快一些。
//将两副BMP图象进行异或操作
procedure TForm1.Button3Click(Sender: TObject);
var
Bmp1,Bmp2 :TBitmap;
begin
Bmp1 :=TBitmap.Create;
Bmp1.Assign(Image1.Picture.Bitmap);
Bmp2 :=TBitmap.Create;
Bmp2.Assign(Image1.Picture.Bitmap);
BitBlt(Bmp2.Canvas.Handle,0,0,Bmp2.Width,Bmp2.Height,Bmp1.Canvas.Handle,0,0,SRCINVERT);
Image2.Picture.Bitmap.Assign(Bmp1);
Bmp1.Free;
Bmp2.Free;
end;
 
怎么SCAN LINE OUT RANGE了?
 
首先要设置成一样大。还和调色板有关。
 
是一样大的
 
我改了一下:

//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;
 
谢谢zw84611
我用SOCKET写了一便
SERVER:
---------------------
procedure TForm1.serverClientRead(Sender: TObject;
Socket: TCustomWinSocket);
var strsize:integer;
buf:pchar;
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:pByteArray;
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时出现了错误?
那么正确的写法是什么?
 
for x := 0 to sizeof(l1)-1 do
改成
for x := 0 to Image1.Picture.Width-1 do
试试。
 
还是一个地方出错~
 
l1 := Bmp2.ScanLine[y];
如果没有这句,l1是空指针。
注意你的l1是针对哪副图的?怎么只有一个Bmp1?
 
我的L1在CLIENT里呀,是接受的SERVER的L3
然后在用接收的来的L1和CLIENT的IMAGE1比较
再把不同行画到BMP1上
 
socket.ReceiveBuf(l1,strsize);之前不妨加一句:getmem(l1,Image1.Picture.Width)
 
照错~~

我想接收应该没问题
调试时,LI[X]是有值的,每次都是和L2[X]比较时出错~~
CLIENT和SERVER的图象是一样大的
 
接收的strsize是否等于Image1.Picture.Width?如果不等,会出错。
 
我把socket.ReceiveBuf(l1,strsize);该成socket.ReceiveBuf(l1,Image1.Picture.Width);
还是错~

 
我不太明白,你的socket.ReceiveBuf()只收到了一行,但
下面就
for y := 0 to Image1.Height-1 do //有Image1.Height行。
begin
l2 := Bmp1.ScanLine[y];
...
这样不是让image1的所有行都和传过来的那一行一样了吗?你应该传一个二维数组才对。

并且l2[x] := l1[x]就可以了,不用写CopyMemory(l2,l1,sizeof(l1));
 
能给出代码吗?
 
兄弟嫌分不够吗?
 
不是不是,是比较麻烦,你可以参考一下远程截屏的代码,把整副图的数据传过来。
分数并不重要,我来这儿是为了消磨时光。
 

Similar threads

回复
0
查看
577
不得闲
回复
0
查看
575
不得闲
回复
0
查看
665
不得闲
S
回复
0
查看
664
swish
S
顶部