如何遍历一幅图像,并对其像素进行比较?

mikko11 2003-03-26 11:22:33
如题
...全文
94 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
mikko11 2003-03-31
  • 打赏
  • 举报
回复
多谢。
xiaocha 2003-03-30
  • 打赏
  • 举报
回复
Pixels太慢,看看TBitmap.ScanLine的帮助
zousoft 2003-03-29
  • 打赏
  • 举报
回复
好! 谢谢 ehom(?!) 指教.
dongdonga 2003-03-29
  • 打赏
  • 举报
回复
学习中...
mikko11 2003-03-28
  • 打赏
  • 举报
回复
大家能否帮我看看,这样行吗?
var
Bmp:TBitmap;
X,Y,x1,y1,sWidth,sHeight:integer;
rgbValue1,rgbValue2,rgbValue3:integer;
k,k1:integer;
begin
Bmp:=TBitmap.Create;
sWidth:=Image1.Width;
sHeight:=Image1.Height;
for k:=0 to 10 do
begin
for x:=0 to sWidth-1 do
begin
for Y:=0 to sHeight-1 do
begin
rgbValue1:=Image1.Picture.Bitmap.Canvas.Pixels[x,y];
rgbValue2:=Image2.Picture.Bitmap.Canvas.Pixels[x,y];
if rgbValue1<>rgbValue2 then
begin
DisA:=x;
DisB:=y;//disa,disb:integer;全局变量
for k1:=0 to 10 do
for x1:=0 to DisA do
for y1:=0 to DisB do
rgbValue3:=Bmp.Canvas.Pixels[x1,y1];
image3.Picture.Bitmap.Assign(bmp);
end else
Exit;
end;
end;
end;
end;
ehom 2003-03-28
  • 打赏
  • 举报
回复
http://expert.csdn.net/Expert/TopicView1.asp?id=1472467
先看看~~~

看看就会明白

1.取像素不要用Bitmap.Canvas.Pixels,用Bitmap.Scanline
2.Pascal里面已经有and,shr这些,没必要把内嵌ASM也搬出来

B:=(Color and $FF0000) shr 16;//这样写多简洁

asm
AND c, 00FF0000h
MOV cl, 16
SHR c, cl
end;
//这样写?没必要!

如果真的要用汇编,这样:

function GetBlue(c: TColor):Byte;
asm
and eax, $00FF0000h
shr eax, $10
end;

应该知道该尽量多用寄存器,这样才快,而且不用mov,第一个参数和返回值都在寄存器eax中

china_dot_com 2003-03-28
  • 打赏
  • 举报
回复
关注
zousoft 2003-03-27
  • 打赏
  • 举报
回复
我编过一个类似的程序, 你参考一下吧:

const
myHeight=383;
myWidth=270;

function GetRed(c: TColor): integer;
begin
asm
AND c, 000000FFh
end;
result:= integer(c);
end;

function GetGreen(c: TColor): integer;
begin
asm
AND c, 0000FF00h
mov cl, 8
shr c, cl
end;
result:= integer(c);
end;

function GetBlue(c: TColor): integer;
begin
asm
AND c, 00FF0000h
mov cl, 16
shr c, cl
end;
result:= integer(c);
end;

procedure TFormMain.btnInvClick(Sender: TObject);
var
i, j, mR, mG, mB: integer;
begin
btnResum.Enabled:=False;
//开始反色处理
for i:= 0 to myHeight-1 do
for j:= 0 to myWidth-1 do
begin
mR:= 255-GetRed(Canvas.Pixels[2+j, 2+i]);
mG:= 255-GetGreen(Canvas.Pixels[2+j, 2+i]);
mB:= 255-GetBlue(Canvas.Pixels[2+j, 2+i]);
asm
mov cl, 16
shl mB, cl
mov cl, 8
shl mG, cl
end;
Canvas.Pixels[396+j, 2+i]:= mB+mG+mR;
end;
btnResum.Enabled:=True;
end;
mikko11 2003-03-27
  • 打赏
  • 举报
回复
谢谢各位。
我想作的是数字剪影,是要比较两幅图的像素,相同的保留,不同的去除。
哪位作过吗?
weibz0525 2003-03-27
  • 打赏
  • 举报
回复
简单的对象素操作用楼上的就可以了/
knife_s 2003-03-27
  • 打赏
  • 举报
回复
Tcanvas中属性Pixels即为像素,

如下:
image1.canvas.pixels[0,0]即为图像0,0坐标像素,怎样比较就看你了

1,183

社区成员

发帖
与我相关
我的任务
社区描述
Delphi GAME,图形处理/多媒体
社区管理员
  • GAME,图形处理/多媒体社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧