注册 登录
编程论坛 C++ Builder

[求助]为什么赋值不对??

IsaacLee 发布于 2006-04-25 21:13, 1171 次点击

pBitmap->Canvas->Pixels[x][y]= currentLayer;
我想把currentLayer的值赋给前面图象中的像素值,但是我通过跟踪发现它根本没有赋过去,为什么啊??难道是类型不对吗?我的currentLayer是整型的!请问这是为什么啊??谢谢!

4 回复
#2
IsaacLee2006-04-26 10:43

请问各位怎么解决啊??很急啊!!有哪位知道的??麻烦解释一下!!谢谢啦!!

#3
Knocker2006-04-26 11:04
贴上代码
#4
IsaacLee2006-04-27 19:04

//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop
#include <Graphics.hpp>

#include "CenterLine.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
struct indexRec {
int row;
int fromCol;
int toCol;
};

TForm1 *Form1;
indexRec indexM[30000];
long int indexP = 0;
int layerInc = 20;
Graphics::TBitmap *pBitmap = new Graphics::TBitmap();

//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}

//---------------------------------------------------------------------------
bool appendPixel2Matrix(int y, int x) {
indexM[indexP].toCol = x;
return true;
}


//---------------------------------------------------------------------------
bool InsertNewSeg2Matrix(int y, int x) {
indexM[indexP].row = y;
indexM[indexP].fromCol = x;
indexM[indexP].toCol = x;
return true;
}


//---------------------------------------------------------------------------
bool isBoard(int x,int y, int currentLayer) {
int xx,yy;
uchar pixelValue;
for(yy=y-1; yy<=y+1; yy++) {
if(yy<0 | yy > pBitmap->Height) continue;
for(xx=x-1; xx<=x+1; xx++) {
if(xx<0 | xx > pBitmap->Width) continue;
if(xx==x & yy==y) continue;
pixelValue = (uchar)pBitmap->Canvas->Pixels[xx][yy];
if(pixelValue==255 | pixelValue== (uchar)(currentLayer-layerInc)) return true;
}
}
return false;
}


//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
pBitmap->PixelFormat = pf8bit;
int currentLayer = 0;
bool segStart = false;
uchar pixelValue;
bool changed = true;
int x,y,i;

indexP = 0;
layerInc = 20;

pBitmap->LoadFromFile("D:\\工程\\中心线\\1001.bmp");
pBitmap->PixelFormat = pf8bit;
// form index matrix
for (y = 0; y < pBitmap->Height; y++) {
segStart = false;
for(x = 0; x < pBitmap->Width; x++) {
pixelValue = (uchar)pBitmap->Canvas->Pixels[x][y];
if(pixelValue==0) { //black pixel
if(segStart) {appendPixel2Matrix(y,x);continue; }
else {InsertNewSeg2Matrix(y,x);segStart=true;continue;}
}
else { //white pixel
if(segStart) {
segStart = false;
indexP++;
if(indexP>=30000) {
ShowMessage("indexP overflow!!");
return;
}
}
}
}
}

// search board pixel by the index of matrix indexM

changed = true;
currentLayer = 10;
while(changed) {
changed = false;
currentLayer += layerInc;
for(i= 0; i<indexP; i++) {
y = indexM[i].row;
for(x=indexM[i].fromCol; x<=indexM[i].toCol;x++) {
//dataPos = y*cvImage->widthStep;
pixelValue = (uchar)pBitmap->Canvas->Pixels[x][y];
if(pixelValue!=0) continue;
if(isBoard(x,y,currentLayer)) {
pBitmap->Canvas->Pixels[x][y]= currentLayer;
changed = true;
}
}
}
//Form1->Canvas->Draw(0,0,pBitmap);
if(!changed) break;
}
Form1->Canvas->Draw(0,0,pBitmap);
}
//---------------------------------------------------------------------------
以上是代码!帮我看看,谢谢啦!!

#5
lxgaaa2006-06-04 12:34

CBC的确不好弄啊调试都难

等有耐心的人来帮忙了

1