[求助]为什么赋值不对??
<P>pBitmap->Canvas->Pixels[x][y]= currentLayer;<BR>我想把currentLayer的值赋给前面图象中的像素值,但是我通过跟踪发现它根本没有赋过去,为什么啊??难道是类型不对吗?我的currentLayer是整型的!请问这是为什么啊??谢谢!</P> <P>请问各位怎么解决啊??很急啊!!有哪位知道的??麻烦解释一下!!谢谢啦!!</P> 贴上代码 <P>//---------------------------------------------------------------------------</P><P>#include <vcl.h><BR>#pragma hdrstop<BR>#include <Graphics.hpp></P>
<P>#include "CenterLine.h"<BR>//---------------------------------------------------------------------------<BR>#pragma package(smart_init)<BR>#pragma resource "*.dfm"<BR>struct indexRec {<BR>int row;<BR>int fromCol;<BR>int toCol;<BR>};</P>
<P>TForm1 *Form1;<BR>indexRec indexM[30000];<BR>long int indexP = 0;<BR>int layerInc = 20;<BR>Graphics::TBitmap *pBitmap = new Graphics::TBitmap();</P>
<P>//---------------------------------------------------------------------------<BR>__fastcall TForm1::TForm1(TComponent* Owner)<BR> : TForm(Owner)<BR>{<BR>}</P>
<P>//---------------------------------------------------------------------------<BR>bool appendPixel2Matrix(int y, int x) {<BR> indexM[indexP].toCol = x;<BR> return true;<BR>}</P>
<P><BR>//---------------------------------------------------------------------------<BR>bool InsertNewSeg2Matrix(int y, int x) {<BR> indexM[indexP].row = y;<BR> indexM[indexP].fromCol = x;<BR> indexM[indexP].toCol = x;<BR> return true;<BR>}</P>
<P><BR>//---------------------------------------------------------------------------<BR>bool isBoard(int x,int y, int currentLayer) {<BR>int xx,yy;<BR>uchar pixelValue;<BR> for(yy=y-1; yy<=y+1; yy++) {<BR> if(yy<0 | yy > pBitmap->Height) continue;<BR> for(xx=x-1; xx<=x+1; xx++) {<BR> if(xx<0 | xx > pBitmap->Width) continue;<BR> if(xx==x & yy==y) continue;<BR> pixelValue = (uchar)pBitmap->Canvas->Pixels[xx][yy];<BR> if(pixelValue==255 | pixelValue== (uchar)(currentLayer-layerInc)) return true;<BR> }<BR> }<BR> return false;<BR>}</P>
<P><BR>//---------------------------------------------------------------------------<BR>void __fastcall TForm1::Button1Click(TObject *Sender)<BR>{<BR>pBitmap->PixelFormat = pf8bit;<BR>int currentLayer = 0;<BR>bool segStart = false;<BR>uchar pixelValue;<BR>bool changed = true;<BR>int x,y,i;</P>
<P>indexP = 0;<BR>layerInc = 20;</P>
<P>pBitmap->LoadFromFile("D:\\工程\\中心线<a>\\1001.bmp</A>");<BR> pBitmap->PixelFormat = pf8bit;<BR>// form index matrix<BR> for (y = 0; y < pBitmap->Height; y++) {<BR> segStart = false;<BR> for(x = 0; x < pBitmap->Width; x++) {<BR> pixelValue = (uchar)pBitmap->Canvas->Pixels[x][y];<BR> if(pixelValue==0) { //black pixel<BR> if(segStart) {appendPixel2Matrix(y,x);continue; }<BR> else {InsertNewSeg2Matrix(y,x);segStart=true;continue;}<BR> }<BR> else { //white pixel<BR> if(segStart) {<BR> segStart = false;<BR> indexP++;<BR> if(indexP>=30000) {<BR> ShowMessage("indexP overflow!!");<BR> return;<BR> }<BR> }<BR> }<BR> }<BR> }</P>
<P>// search board pixel by the index of matrix indexM</P>
<P> changed = true;<BR> currentLayer = 10;<BR> while(changed) {<BR> changed = false;<BR> currentLayer += layerInc;<BR> for(i= 0; i<indexP; i++) {<BR> y = indexM[i].row;<BR> for(x=indexM[i].fromCol; x<=indexM[i].toCol;x++) {<BR> //dataPos = y*cvImage->widthStep;<BR> pixelValue = (uchar)pBitmap->Canvas->Pixels[x][y];<BR> if(pixelValue!=0) continue;<BR> if(isBoard(x,y,currentLayer)) {<BR> pBitmap->Canvas->Pixels[x][y]= currentLayer;<BR> changed = true;<BR> }<BR> }<BR> }<BR> //Form1->Canvas->Draw(0,0,pBitmap);<BR> if(!changed) break;<BR> }<BR> Form1->Canvas->Draw(0,0,pBitmap);<BR>}<BR>//---------------------------------------------------------------------------<BR>以上是代码!帮我看看,谢谢啦!!</P> <P>CBC的确不好弄啊调试都难<BR></P>
<P>等有耐心的人来帮忙了</P>
页:
[1]
