编程论坛's Archiver

IsaacLee 发表于 2006-4-25 21:13

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

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

IsaacLee 发表于 2006-4-26 10:43

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

Knocker 发表于 2006-4-26 11:04

贴上代码

IsaacLee 发表于 2006-4-27 19:04

<P>//---------------------------------------------------------------------------</P>
<P>#include &lt;vcl.h&gt;<BR>#pragma hdrstop<BR>#include &lt;Graphics.hpp&gt;</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&lt;=y+1; yy++)  {<BR>        if(yy&lt;0 | yy &gt; pBitmap-&gt;Height) continue;<BR>        for(xx=x-1; xx&lt;=x+1; xx++)  {<BR>            if(xx&lt;0 | xx &gt; pBitmap-&gt;Width) continue;<BR>            if(xx==x &amp; yy==y) continue;<BR>                       pixelValue = (uchar)pBitmap-&gt;Canvas-&gt;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-&gt;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-&gt;LoadFromFile("D:\\工程\\中心线<a>\\1001.bmp</A>");<BR>    pBitmap-&gt;PixelFormat = pf8bit;<BR>// form index matrix<BR>    for (y = 0; y &lt; pBitmap-&gt;Height; y++)  {<BR>                segStart = false;<BR>        for(x = 0; x &lt; pBitmap-&gt;Width; x++)  {<BR>           pixelValue = (uchar)pBitmap-&gt;Canvas-&gt;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&gt;=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&lt;indexP; i++)  {<BR>            y = indexM[i].row;<BR>            for(x=indexM[i].fromCol; x&lt;=indexM[i].toCol;x++) {<BR>                //dataPos = y*cvImage-&gt;widthStep;<BR>                pixelValue = (uchar)pBitmap-&gt;Canvas-&gt;Pixels[x][y];<BR>                if(pixelValue!=0) continue;<BR>                if(isBoard(x,y,currentLayer))  {<BR>                                        pBitmap-&gt;Canvas-&gt;Pixels[x][y]= currentLayer;<BR>                    changed = true;<BR>                }<BR>            }<BR>        }<BR>        //Form1-&gt;Canvas-&gt;Draw(0,0,pBitmap);<BR>        if(!changed) break;<BR>    }<BR>    Form1-&gt;Canvas-&gt;Draw(0,0,pBitmap);<BR>}<BR>//---------------------------------------------------------------------------<BR>以上是代码!帮我看看,谢谢啦!!</P>

lxgaaa 发表于 2006-6-4 12:34

<P>CBC的确不好弄啊调试都难<BR></P>
<P>等有耐心的人来帮忙了</P>

页: [1]

Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.