⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainform.cpp

📁 C++ BUILDER精彩编程实例集锦(源码)2 第三部分 文件操作 第四部分 图像处理
💻 CPP
字号:
//---------------------------------------------------------------------------

#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)
{
   if(this->OpenPictureDialog1->Execute())
   {
     AnsiString StrFile=this->OpenPictureDialog1->FileName;
     this->Image1->Picture->LoadFromFile(StrFile);
   }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn3Click(TObject *Sender)
{
   this->Close();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::BitBtn2Click(TObject *Sender)
{
  this->Label1->Caption="正在进行图像柔化处理...               ";
  this->Label1->Update();
  int iHeight=this->Image1->Picture->Width;
  int iWidth=this->Image1->Picture->Height;
  //高斯模板
  int Gauss[9]={1,2,1,2,4,2,1,2,1};
  for(int x=1;x<iWidth-1;x++)
    for(int y=1;y<iHeight-1;y++)
    {
       int r=0,g=0,b=0;
       int Index=0;
       for(int col=-1;col<=1;col++)
        for(int row=-1;row<=1;row++)
	{
	  COLORREF pixel=this->Image1->Canvas->Pixels[x+row][y+col];
	  r+=GetRValue(pixel)*Gauss[Index];
	  g+=GetGValue(pixel)*Gauss[Index];
	  b+=GetBValue(pixel)*Gauss[Index];
	  Index++;
	 }
	 r/=16;
	 g/=16;
	 b/=16;
	 //处理颜色值溢出
	 r=r>255?255:r;
	 r=r<0?0:r;
	 g=g>255?255:g;
	 g=g<0?0:g;
	 b=b>255?255:b;
	 b=b<0?0:b;
       this->Image1->Canvas->Pixels[x-1][y-1]=RGB(r,g,b);
   }
  this->Label1->Caption="图像柔化处理完毕!";
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

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