| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1171 人关注过本帖
标题:[求助]为什么赋值不对??
只看楼主 加入收藏
IsaacLee
Rank: 1
等 级:新手上路
帖 子:70
专家分:0
注 册:2006-3-2
收藏
 问题点数:0 回复次数:4 
[求助]为什么赋值不对??

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

搜索更多相关主题的帖子: 赋值 
2006-04-25 21:13
IsaacLee
Rank: 1
等 级:新手上路
帖 子:70
专家分:0
注 册:2006-3-2
收藏
得分:0 

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

2006-04-26 10:43
Knocker
Rank: 8Rank: 8
等 级:贵宾
威 望:47
帖 子:10454
专家分:603
注 册:2004-6-1
收藏
得分:0 
贴上代码

九洲方除百尺冰,映秀又遭蛮牛耕。汽笛嘶鸣国旗半,哀伤尽处是重生。     -老K
治国就是治吏。礼义廉耻,国之四维。四维不张,国之不国。   -毛泽东
2006-04-26 11:04
IsaacLee
Rank: 1
等 级:新手上路
帖 子:70
专家分:0
注 册:2006-3-2
收藏
得分:0 

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

#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);
}
//---------------------------------------------------------------------------
以上是代码!帮我看看,谢谢啦!!

2006-04-27 19:04
lxgaaa
Rank: 1
等 级:新手上路
帖 子:59
专家分:0
注 册:2006-5-17
收藏
得分:0 

CBC的确不好弄啊调试都难

等有耐心的人来帮忙了


天高任鸟飞,海阔任鱼翱
2006-06-04 12:34
快速回复:[求助]为什么赋值不对??
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.023123 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved