我再寫區域成長法時出現Access Violation |
尚未結案
|
chemichemi
一般會員 ![]() ![]() 發表:5 回覆:5 積分:2 註冊:2005-03-19 發送簡訊給我 |
其實只是類似區域成長法 也不確定對不對
但是我想要將一張圖片中的一個由使用者指定的點
來找出該點周圍相關的顏色
compilier都沒問題
但是執行bcb就當了
如果build all project 之後
再執行該執行檔
使用到那個部分 就會出現
Access violation at address 00403AC in module'cap.exe'
Read of address 00000420 功力不足實在找不出問題所在
希望大家一起幫忙看一下 程式的部分:
//宣告 const int max_stack_size=1000; typedef struct{ int xx; int yy; int rr; int gg; int bb; }stack; stack rgstack[max_stack_size]; int top=-1; bool stack_full(int top){ if(top==max_stack_size){ return true; }else{ return false; } } bool stack_empty(int top){ if(top<0){ return true; }else{ return false; } } void add_to_stack(int x,int y,int t,stack sk[]){ t ; sk[top].xx=x; sk[top].yy=y; sk[top].rr=GetRValue(Form1->Image2->Canvas->Pixels[x][y]); sk[top].gg=GetGValue(Form1->Image2->Canvas->Pixels[x][y]); sk[top].bb=GetBValue(Form1->Image2->Canvas->Pixels[x][y]); } void delete_from_stack(int pointer){ pointer--; } void chackRGB(stack sk[],int x,int y,int pointer,int target){ bool chackornot=false; for(int chacked=0; chacked<=pointer; chacked ){ if(sk[chacked].xx==x && sk[chacked].yy ==y){ chackornot=true; } } if(!chackornot){ if(abs(GetRValue(Form1->Image2->Canvas->Pixels[x][y])-sk[target].rr)<=10){ add_to_stack(x,y,top,rgstack); } } } void changecolor(int x,int y){ Byte *ptrchngcolor; ptrchngcolor = (Byte *)Form1->Image2->Picture->Bitmap->ScanLine[y]; ptrchngcolor[x*3]=(Byte)0; ptrchngcolor[x*3 1]=(Byte)0; ptrchngcolor[x*3 2]=(Byte)0; } //程式中使用的部分 void __fastcall TForm1::Image2MouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { if(rgswitch){ if(Button == mbLeft){ add_to_stack(X,Y,top,rgstack); for(int bottom=0;bottom<=top;bottom ){ chackRGB(rgstack,X-1,Y,top,bottom); chackRGB(rgstack,X 1,Y,top,bottom); chackRGB(rgstack,X,Y-1,top,bottom); chackRGB(rgstack,X,Y 1,top,bottom); } while(!stack_empty(top)){ changecolor(rgstack[top].xx,rgstack[top].yy); delete_from_stack(top); } } } }發表人 - chemichemi 於 2005/10/15 21:47:17 |
jcjroc
高階會員 ![]() ![]() ![]() ![]() 發表:21 回覆:279 積分:115 註冊:2002-09-18 發送簡訊給我 |
|
justdo
高階會員 ![]() ![]() ![]() ![]() 發表:2 回覆:359 積分:222 註冊:2004-08-17 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |