unit3.cpp

来自「C++Builder高级应用开发指南随书源码」· C++ 代码 · 共 60 行

CPP
60
字号
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit3.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm3 *Form3;
//---------------------------------------------------------------------------
__fastcall TForm3::TForm3(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm3::FormCreate(TObject *Sender)
{
   register int x,y;
   register int Left,Right;
   bool FlagLeft;
   HRGN tepRgn,WndRgn;
   Image1->Picture->LoadFromFile(".\\rose.bmp");
   Width=Image1->Width;
   Height=Image1->Height;
   WndRgn=CreateRectRgn(0,0,Width,Height);
   for(y=0;y<Height;y++)
   {
      FlagLeft=false;
      for(x=0;x<Width;x++)
      {
         //发现了线段左边的第一个白点
         if(Image1->Canvas->Pixels[x][y]==clWhite&&FlagLeft==false)
         {
             Left=x;
             FlagLeft=true;
         }
         //发现了线段右边的第一个非白点
         else if(Image1->Canvas->Pixels[x][y]!=clWhite&&FlagLeft==true)
         {
            Right=x;
            tepRgn=CreateRectRgn(Left,y,Right,y+1);
            CombineRgn(WndRgn,WndRgn,tepRgn,RGN_XOR);
            DeleteObject(tepRgn);
            FlagLeft=false;
         }
      }
      //处理图像右边的白色区域
      if(FlagLeft==true&&x>=Width)
      {
          tepRgn=CreateRectRgn(Left,y,x,y+1);
          CombineRgn(WndRgn,WndRgn,tepRgn,RGN_XOR);
          DeleteObject(tepRgn);
      }
   }
   SetWindowRgn(Handle,WndRgn,true);
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?