画点的速度~~太慢了~(50分)

L

logpie

Unregistered / Unconfirmed
GUEST, unregistred user!
我截了2副图象(1024*768),用CANVAS。PIXEL[X,Y]把第二图不同的象素画到前一张
图中,可是速度太慢了(大概要十几秒),有什么方法能快起来?
我只是画不同点,所以SCANLINE和COPYRECT用起来也不方便~~
 
试试多线程。
 
只能让人感到前台不停顿呀~
速度还一个样
 
我的意思是多个线程同时画不同的部分。
 
用Direct X吧
 
你用pixles当然慢。。。
不过不明白。。。你最后的效果不就是让前一张图跟第二张图一样了吗?
干吗不直接拷贝?
 
兄弟,我在处理照片背景透明时也碰到过这个问题,老实说,当初我也觉得用SCANLINE很麻烦,
但是用了之后才发现很简单,所以,要想提高速度,老老实实的用它

相信我,没错的 :)
 
兄弟能给个SCANLINE的实现吗?
 
//这里假设你的两幅图像都是256色的,并且要比较的两幅图像大小完全一样
procedure DrawDiffenentPoint(C1,C2:TBitMap);
var
P1,P2:pByteArray;
i,j:integer;
begin
C1.PixelFormat:=pf8bit;
C2.PixelFormat:=pf8bit;
for i:=0 to C1.Height-1 do
begin
P1;=C1.ScanLine;
P2;=C2.ScanLine;
for j:=0 to C1.Width-1 do
if P1[j]<>P2[j] then P1[j]:=0;//把不同的电画成黑色
end;
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;
 
多人接受答案了。
 
顶部