为什么网上找的这个代码比较不出两张图呢?(50)

  • 主题发起人 主题发起人 xf_z
  • 开始时间 开始时间
X

xf_z

Unregistered / Unconfirmed
GUEST, unregistred user!
用TextOut画图后好像没改变图一样,用比较图的函数试了下也是两张图一样,事实上两张图不一样啊procedure TForm1.Button1Click(Sender: TObject);beginTemp :=334; Image1.Canvas.TextOut( 0, 0, '12334' ); TextWidth := Image1.Canvas.TextWidth ( '12334' ); TextHeight := Image1.Canvas.TextHeight ( '12334' ); Image2.Canvas.TextOut ( 0, 0, IntToStr ( Temp ) ); TmpWidth := Image2.Canvas.TextWidth ( IntToStr ( Temp ) ); TmpHeight := Image2.Canvas.TextHeight ( IntToStr ( Temp ) );end;procedure TForm1.Button2Click(Sender: TObject);var TempStr : String; i, j, k : Integer; Flag : boolean; TmpColor : DWORD; Mark : Integer; OldColorPtr : PByteArray; TmpColorPtr : PByteArray;begin Mark := 0; for i := 0 to TmpHeight - 1 do begin OldColorPtr := Image1.Picture.Bitmap.ScanLine [ i ]; TmpColorPtr := Image2.Picture.Bitmap.ScanLine [ i ]; Flag := true; j := Mark; while j < TextWidth do begin for k := 0 to TmpWidth do begin if OldColorPtr [j + k] <> TmpColorPtr[k] then begin Flag := false; break; end; end; inc ( j ); end; if Flag and ( (j - k) > 0 ) then Mark := j - k else Mark := 0; end; if Flag then ShowMessage ( 'Find the text at '+ IntToStr (Mark - TmpWidth + 1) + ',0'); Image1.Canvas.Pen.Color := RGB ( $FF, $00, $00 ); Image1.Canvas.Brush.Style := bsClear; Image1.Canvas.Rectangle( Mark - TmpWidth + 1, 0, Mark, TmpHeight );end;
 
procedure TForm1.Button1Click(Sender: TObject);begin Temp :=334; Image1.Canvas.TextOut( 0, 0, '121334' ); TextWidth := Image1.Canvas.TextWidth ( '121334' ); TextHeight := Image1.Canvas.TextHeight ( '121334' ); Image2.Canvas.TextOut ( 0, 0, IntToStr ( Temp ) ); TmpWidth := Image2.Canvas.TextWidth ( IntToStr ( Temp ) ); TmpHeight := Image2.Canvas.TextHeight ( IntToStr ( Temp ) ); end;function TForm1.BmpLK(bmp1,bmp2:Tbitmap): Boolean;var p1,p2:pbytearray; x,y,x1,y1,k,Gray:integer; bmp,bmpB:Tbitmap;begin result := False; k := 0; bmp:=Tbitmap.Create; bmp.Assign(bmp1); bmp.PixelFormat:=pf24bit; bmpB:=Tbitmap.Create; bmpB.Assign(bmp2); bmpB.PixelFormat:=pf24bit; if bmp.Height>=bmpB.Height then begin y1 := bmpB.Height; end else begin y1 := bmp.Height; end; if bmp.Width>=bmpB.Width then begin x1 := bmpB.Width; end else begin x1 := bmp.Width; end; for y:=1 to y1-1 do begin p1:=bmp.ScanLine[y]; p2:=bmpB.ScanLine[y]; for x:=1 to x1-1 do begin if p1[3*x]<>p2[3*x] then begin inc(k); Gray := 0; p2[3*x] := Gray; p2[3*x+1] := Gray; p2[3*x+2] := Gray; end; end; end; bmp2.Assign(bmpB); if k>0 then begin result := True; end; bmp.Free; bmpB.Free;end;procedure TForm1.Button2Click(Sender: TObject);begin if BmpLK(Image1.Picture.Bitmap,Image2.Picture.Bitmap) then begin showmessage('两张图存在差异!'); end;end;
 

Similar threads

I
回复
0
查看
664
import
I
I
回复
0
查看
771
import
I
I
回复
0
查看
843
import
I
I
回复
0
查看
687
import
I
后退
顶部