delphi之找色和色块
找色和色塊,是模擬的重要基礎。
有時候,需要確定某點是否出現某種顏色,有時候需要判斷色塊是否出現在某位置
有時候,需要看范圍內是否出現色塊。
function IsColor(bmp:TBitmap; x,y:integer; c:TColor):boolean;
var
? row:pRGBTripArray;
? p:TRGBTriple;
begin
? row:=bmp.ScanLine[y];
? p:=row[x];
? result:=(p.rgbtBlue=GetBValue(c)) and (p.rgbtGreen=GetGValue(c))
??????? and (p.rgbtRed=GetRValue(c));
end;
function IsColorBlock(bmp:TBitmap; x,y,n:integer; c:TColor):boolean;
var
? i,j:integer;
begin
? result:=false;
? for j:=y to y+n-1 do
? begin
??? for i:=x to x+n-1 do
??? begin
????? if not IsColor(bmp, i, j, c) then // 顏色不對就不是色塊了
??????? exit;
???? end;
? end;
? result:=true; // 能到這里,該位置就是色塊
end;
function FindColorBlock(bmp:TBitmap; x1,y1,x2,y2,n:integer;c:TColor):TPoint;
var
? i,j:integer;
begin
? for j:=y1 to y2 do
? begin
??? for i:=x1 to x2 do
??? begin
????? if IsColor(bmp, i, j, c) then // 先找色點
????? begin
??????? if IsColorBlock(bmp,i,j,3,c) then // 再判色塊
??????? begin
????????? result.x:=i;
????????? result.y:=j;
????????? exit; // 找到返回
??????? end;
????? end;
??? end;
? end;
? result.x:=-1;
? result.y:=-1;
end;
轉載于:https://www.cnblogs.com/MaxWoods/archive/2013/05/29/3106274.html
總結
以上是生活随笔為你收集整理的delphi之找色和色块的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【译】Angular 开发44条“军规”
- 下一篇: GB 18030介绍及其与相关标准的比较