主题:拜託幫幫我吧
void __fastcall TForm1::Button1Click(TObject *Sender)
{
{
int projv[1000],projh[1000];
TheBitMap=Image1->Picture->Bitmap;
for(int i=0;i<1000;i++)
{
projv[i]=0;
projh[i]=0;
}
for(int y=0;y<height;y++)
{
ptr1=(Byte*)TheBitMap->ScanLine[y];
for(int x=0;x<width;x++)
newimg[x][y]=ptr1[x];
}
for(int y=0;y<height;y++)
for(int x=0;x<width;x++)
if(newimg[x][y]==0)
projh[y]++;
for(int x=0;x<width;x++)
for(int y=0;y<height;y++)
if(newimg[x][y]==0)
projv[x]++;
int temp;
int linetop[10],linebot[10],res[10];
temp=0;
for(int y=0;y<height-1;y++)
{
if(projh[y]==0&&projh[y+1]>0)
linetop[temp]=y+1;
if(projh[y]>0&&projh[y+1]==0)
{
linebot=[temp]=y;
if(linebot[temp]-linetop[temp]>=5)
temp++;
}
}
TheBitMap->PixelFormat=pf24bit;
Image1->Canvas->Pen->Color=clRed;
Image1->Canvas->Pen->Width=2;
Image1->Canvas->MoveTo(width-projh[0],0);
for(int i=1;i<height;i++)
Image1->Canvas->LineTo(width-projh[i],i);
for(int i=0;i<temp;i++)
{
for(int x=0;x<width;x++)
{
projv[x]=0;
for(int y=linetop[i];y<=linebot[i];y++)
if(newimg[x][y]==0)
projv[x]++;
}
Image1->Canvas->MoveTo(0,linebot[i]+30-projv[0]);
for(int j=1;j<width-1;j++)
Image1->Canvas->LineTo(j,linebot[i]+30-projv[j]);
res[i]=0;
for(int x=0;x<width-1;x++)
if(projv[x]==0&&projv[x+1]>0)
res[i]++;
Memo1->Lines->Add(IntToStr(i));
Memo2->Lines->Add(IntToStr(res[i]));
}
}
}
{
{
int projv[1000],projh[1000];
TheBitMap=Image1->Picture->Bitmap;
for(int i=0;i<1000;i++)
{
projv[i]=0;
projh[i]=0;
}
for(int y=0;y<height;y++)
{
ptr1=(Byte*)TheBitMap->ScanLine[y];
for(int x=0;x<width;x++)
newimg[x][y]=ptr1[x];
}
for(int y=0;y<height;y++)
for(int x=0;x<width;x++)
if(newimg[x][y]==0)
projh[y]++;
for(int x=0;x<width;x++)
for(int y=0;y<height;y++)
if(newimg[x][y]==0)
projv[x]++;
int temp;
int linetop[10],linebot[10],res[10];
temp=0;
for(int y=0;y<height-1;y++)
{
if(projh[y]==0&&projh[y+1]>0)
linetop[temp]=y+1;
if(projh[y]>0&&projh[y+1]==0)
{
linebot=[temp]=y;
if(linebot[temp]-linetop[temp]>=5)
temp++;
}
}
TheBitMap->PixelFormat=pf24bit;
Image1->Canvas->Pen->Color=clRed;
Image1->Canvas->Pen->Width=2;
Image1->Canvas->MoveTo(width-projh[0],0);
for(int i=1;i<height;i++)
Image1->Canvas->LineTo(width-projh[i],i);
for(int i=0;i<temp;i++)
{
for(int x=0;x<width;x++)
{
projv[x]=0;
for(int y=linetop[i];y<=linebot[i];y++)
if(newimg[x][y]==0)
projv[x]++;
}
Image1->Canvas->MoveTo(0,linebot[i]+30-projv[0]);
for(int j=1;j<width-1;j++)
Image1->Canvas->LineTo(j,linebot[i]+30-projv[j]);
res[i]=0;
for(int x=0;x<width-1;x++)
if(projv[x]==0&&projv[x+1]>0)
res[i]++;
Memo1->Lines->Add(IntToStr(i));
Memo2->Lines->Add(IntToStr(res[i]));
}
}
}