我現在正在撰寫一個簡單的圖型配對的程式~~ 不過發現ㄧ些問題~~想請問一些知道的大大~~ 1.我的for迴圈這樣撰寫對嗎?
2.判斷式這樣撰寫對嗎? 我有一張大的影像A~~和一張小的影像B~~~而B是從A中切割出來的~~
所以一定會配對成功~~不過我的程式好像不對~~~它可以run不過卻不是我要的執行
一按下配對按鈕~~圖形A和B就消失了~~~@@
以下我附上我所寫的程式碼~~~
#include
#pragma hdrstop #include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender)
{
Graphics:: TBitmap *TheBitmap , *TheBitmap1;
Byte *ptr;
int x,y,a,b; //x.y是大張影像的寬.高 a.b是小張影像的高.寬
int sum;
TheBitmap=Image1->Picture->Bitmap;
TheBitmap1=Image2->Picture->Bitmap; //這邊不是說要把指標定好~~把指標指在影像的每一個pixel嗎??
我原本TheBitmap=Image2->Picture->Bitmap;是這樣寫的~~
不過有大大指出我這有問題~~所以我有看了一下一些參考程式想想~~TheBitmap1=Image2->Picture->Bitmap;
好像才是對的
for (y=0;yScanLine[y];
for (x=0;x<(x-b);x=x+b)
{
ptr=(Byte*)TheBitmap->ScanLine[x];
for (a=0;aHeight;a++)
{
ptr=(Byte*)TheBitmap1->ScanLine[a];
for (b=0;bWidth;b++)
{
sum=(ptr[y*3]-ptr[a*3])+ (ptr[y*3+1]-ptr[a*3+1])+
(ptr[y*3+2]-ptr[a*3+2]); //判斷式
sum=(ptr[x*3]-ptr[b*3])+ (ptr[x*3+1]-ptr[b*3+1])+
(ptr[x*3+2]-ptr[b*3+2]); //判斷式
}
}
}
}
if(sum=0)
{
ptr[a*3]=ptr[y*3];
ptr[a*3+1]=ptr[y*3+1];
ptr[a*3+2]=ptr[y*3+2];
ptr[b*3]=ptr[x*3];
ptr[b*3+1]=ptr[x*3+1];
ptr[b*3+2]=ptr[x*3+2];
}
Repaint();
}
//---------------------------------------------------------------------------
以下是我的程式介面:
發表人 - vinbaby 於 2005/07/16 11:35:32