尋邊貼標籤 請前輩看看程式有沒有問題! |
|
mp_0223
一般會員 發表:16 回覆:32 積分:9 註冊:2006-10-02 發送簡訊給我 |
小地做了一個尋邊貼標籤程式 執行時沒問題 但不知道有沒有貼到標籤
想請各位前輩幫小弟看看有沒有問題!! void __fastcall TForm1::Button7Click(TObject *Sender) { int label; Bitmap1->LoadFromFile("C.bmp"); Image2->Picture->Assign(Bitmap1); pBitmap1->Assign(Image2->Picture->Bitmap); pBitmap1->PixelFormat = pf24bit;//24bit Byte *ptr; for (int i=0;i { ptr=(Byte*)Bitmap1->ScanLine[i]; for (int j=0;j { p2[j][i]=ptr[j*3]; label=L_BASE; } } for (int i=0;i { ptr=(Byte*)Bitmap1->ScanLine[i]; for (int j=0;j { if(p2[j][i]==clBlack) { if(label>=clBlack) { ptr[j*3]=Filter2(j,i);label ; ptr[j*3 1]=Filter2(j,i);label ; ptr[j*3 2]=Filter2(j,i);label ; } } } } Image2->Stretch=true; Image2->Height *=1; Image2->Width *=1; Image2->Picture->Assign(Bitmap1); Image2->Picture->SaveToFile("D.bmp"); delete Bitmap1; } //--------------------------------------------------------------------------- int __fastcall TForm1::Filter2(int i,int j) { int label; int cnt=0; int im=i-1,ip=i 1,jm=j-1,jp=j 1; int p[10]; p[1]=p2[i-1][j-1]; p[2]=p2[i][j-1]; p[3]=p2[i 1][j-1]; p[4]=p2[i-1][j]; p[5]=p2[i][j]; p[6]=p2[i 1][j]; p[7]=p2[i-1][j 1]; p[8]=p2[i][j 1]; p[9]=p2[i 1][j 1]; for (int i=0;i { for (int j=0;j { if(Bitmap1->Canvas->Pixels[i][j] == label) { if(im<0)im=0;if(ip>Height-1) ip=Height-1; if(jm<0)im=0;if(jp>Width-1) ip=Width-1; // 判斷 (x 1,y) if(Bitmap1->Canvas->Pixels[i 1][j] == clWhite) { p[6]==label;cnt ; } // 判斷 (x 1, y-1) if(Bitmap1->Canvas->Pixels[i 1][j-1] == clWhite) { p[3]==label;cnt ; } // 判斷 (x,y-1) if(Bitmap1->Canvas->Pixels[i][j-1] == clWhite) { p[2]==label;cnt ; } // 判斷 (x-1,y-1) if(Bitmap1->Canvas->Pixels[i-1][j-1] == clWhite) { p[1]==label;cnt ; } // 判斷 (x-1,y) if(Bitmap1->Canvas->Pixels[i-1][j] == clWhite) { p[4]==label;cnt ; } // 判斷 (x-1,y 1) if(Bitmap1->Canvas->Pixels[i-1][j 1] == clWhite) { p[7]==label;cnt ; } // 判斷 (x,y 1) if(Bitmap1->Canvas->Pixels[i][j 1] == clWhite) { p[8]==label;cnt ; } // 判斷 (x 1,y 1) if(Bitmap1->Canvas->Pixels[i 1][j 1] == clWhite) { p[9]==label;cnt ; } } if (cnt==0)break; } } return (cnt); } |
mp_0223
一般會員 發表:16 回覆:32 積分:9 註冊:2006-10-02 發送簡訊給我 |
|
mp_0223
一般會員 發表:16 回覆:32 積分:9 註冊:2006-10-02 發送簡訊給我 |
|
justdo
高階會員 發表:2 回覆:359 積分:222 註冊:2004-08-17 發送簡訊給我 |
|
mp_0223
一般會員 發表:16 回覆:32 積分:9 註冊:2006-10-02 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |