mainform.cpp
来自「C++ BUILDER精彩编程实例集锦(源码) 第一部分 界面设计 第二部分」· C++ 代码 · 共 96 行
CPP
96 行
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Mainform.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{
this->Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::OnCreate(TObject *Sender)
{
register int x,y;
int l,r;
POINT *a;
bool bCount,bHeight;
HRGN WndRgn,TRgn1,TRgn2;
if((a=(POINT *)malloc(800*4*(sizeof(POINT))))==NULL)
{
MessageBox(Handle,"分配内存失败!","信息提示",MB_OK);
exit(0);
}
Width=Image1->Width;
Height=Image1->Height;
//重绘窗口,使窗口大小等于图像大小
Repaint();
l=0;
r=Image1->Height*2-1;
WndRgn=CreateRectRgn(0,0,Image1->Width,Image1->Height);
//产生轮廓坐标点数组
for(y=0;y<Image1->Height;y++)
{
bCount=true;
for(x=0;x<Image1->Width;x++)
if(Image1->Canvas->Pixels[x][y]!=clWhite)
{
a[l].x=x+1;
a[l].y=y;
bCount=false;
break;
}
if(bCount)
a[l]=a[l-1];
l++;
bHeight=true;
for(x=Image1->Width-1;x>=0;x--)
//根据去掉部分的具体颜色而定,此例为白色clWhite
if(Image1->Canvas->Pixels[x][y]!=clWhite)
{
a[r].x=x;
a[r].y=y;
bHeight=false;
break;
}
if(bHeight)
a[r]=a[r+1];
r--;
}
// 抠去图片内凹部分
r=Image1->Height*2-1;
for(y=0;y<Image1->Height;y++)
{
for(x=a[y].x;x<a[r].x;x++)
if(Image1->Canvas->Pixels[x][y]==clWhite)
{
TRgn2=CreateRectRgn(x,y,x+1,y+1);
CombineRgn(WndRgn,WndRgn,TRgn2,RGN_XOR);
DeleteObject(TRgn2);
}
r--;
}
//将图片外围部分抠去
TRgn1=CreatePolygonRgn(a,Image1->Height*2,ALTERNATE);
CombineRgn(WndRgn,WndRgn,TRgn1,RGN_AND);
DeleteObject(TRgn1);
free(a);
//显示不规则窗体
SetWindowRgn(Handle,WndRgn,true);
SetWindowPos(Handle,HWND_TOP,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?