//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include "graphics.hpp" //包含图像的头文件
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
int x,y,i,j;
Graphics::TBitmap *Bitmap;
int yz;
//int processing;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::OpenClick(TObject *Sender)
{
AnsiString filename;
TColor color;
if(OpenP->Execute())
{
filename=OpenP->FileName;
SImg->Picture->LoadFromFile(filename);
x=SImg->Picture->Width;
y=SImg->Picture->Height;
//影响图片导入
/* for(i=0;i<x-1;i++)
{
for(j=0;j<y-1;j++)
{
color=SImg->Canvas->Pixels[i][j];
rgbp[i][j].r=GetRValue(color);
rgbp[i][j].g=GetGValue(color);
rgbp[i][j].b=GetBValue(color);
} */
Bitmap=new Graphics::TBitmap;
Bitmap->Width=SImg->Picture->Width;
Bitmap->Height=SImg->Picture->Height;
// }
//SImg是Image的ID,是显示元图片的容器
//打开文件
// delete Bitmap;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::SaveClick(TObject *Sender)
{
AnsiString filename;
if(SaveP->Execute())
{
filename=SaveP->FileName;
SaveP->DefaultExt=".BMP";
//设置缺省扩展名
DImg->Picture->SaveToFile(filename);
//DImg是Image的ID,是显示元图片的容器
//存储文件
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ClearClick(TObject *Sender)
{
SImg->Picture->Assign(NULL);
DImg->Picture->Assign(NULL);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::E1Click(TObject *Sender)
{
Close();
}
//----------------------------------------------------------------------------
TForm1::GetRgbp(TObject *Sender)
{
TColor color;
x=SImg->Width;
y=SImg->Height;
for(i=1;i<x-1;i++)
{
for(j=1;j<y-1;j++)
{
color=SImg->Canvas->Pixels[i][j];
rgbp[i][j].r=GetRValue(color);
rgbp[i][j].g=GetGValue(color);
rgbp[i][j].b=GetBValue(color);
}
}
return 0;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::SmoothClick(TObject *Sender)
{
//柔化处理
int red,green,blue;
//SImg->Picture->Bitmap->Assign(DImg->Picture->Bitmap); //使原图像变为转化后的图像
GetRgbp(Sender);
//去的颜色信息
for(i=1;i<x-2;i++)
{
for(j=1;j<y-2;j++)
{
red=rgbp[i-1][j-1].r+rgbp[i-1][j].r+rgbp[i-1][j+1].r+
rgbp[i][j-1].r+rgbp[i][j].r+rgbp[i][j+1].r+
rgbp[i+1][j-1].r+rgbp[i+1][j].r+rgbp[i+1][j+1].r;
green=rgbp[i-1][j-1].g+rgbp[i-1][j].g+rgbp[i-1][j+1].g+
rgbp[i][j-1].g+rgbp[i][j].g+rgbp[i][j+1].g+
rgbp[i+1][j-1].g+rgbp[i+1][j].g+rgbp[i+1][j+1].g;
blue=rgbp[i-1][j-1].b+rgbp[i-1][j].b+rgbp[i-1][j+1].b+
rgbp[i][j-1].b+rgbp[i][j].b+rgbp[i][j+1].b+
rgbp[i+1][j-1].b+rgbp[i+1][j].b+rgbp[i+1][j+1].b;
//颜色处理
Bitmap->Canvas->Pixels[i][j]=TColor(RGB(red/9,green/9,blue/9));
}
}
DImg->Picture->Bitmap->Assign(Bitmap);
//平滑处理
}
//---------------------------------------------------------------------------
void __fastcall TForm1::SharpClick(TObject *Sender)
{
//锐化处理
int red,green,blue;
// SImg->Picture->Bitmap->Assign(DImg->Picture->Bitmap);//使原图像变为转化后的图像
GetRgbp(Sender);
//取得颜色信息
for(i=1;i<x-2;i++)
{
for(j=1;j<y-2;j++)
{
red=rgbp[i][j].r+0.5*(rgbp[i][j].r-rgbp[i-1][j-1].r);
green=rgbp[i][j].g+0.5*(rgbp[i][j].g-rgbp[i-1][j-1].g);
blue=rgbp[i][j].b+0.5*(rgbp[i][j].b-rgbp[i-1][j-1].b);
if(red>255) red=255;
if(red<0)red=0;
if(green>255) green=255;
if(green<0)green=0;
if(blue>255) blue=255;
if(blue<0)blue=0;
Bitmap->Canvas->Pixels[i][j]=TColor(RGB(red,green,blue));
}
}
DImg->Picture->Bitmap->Assign(Bitmap);
//锐化处理
}
//---------------------------------------------------------------------------
void __fastcall TForm1::EmbossClick(TObject *Sender)
{
//浮雕效果
int red,green,blue;
//SImg->Picture->Bitmap->Assign(DImg->Picture->Bitmap);//使原图像变为转化后的图像
GetRgbp(Sender);
for(i=1;i<x-2;i++)
{
for(j=1;j<y-2;j++)
{
red=rgbp[i][j].r+0.5*(rgbp[i+1][j+1].r+128);
green=rgbp[i][j].g+0.5*(rgbp[i+1][j+1].g+128);
blue=rgbp[i][j].b+0.5*(rgbp[i+1][j+1].b+128);
//颜色处理
if(red>255) red=255;
if(red<0)red=0;
if(green>255) green=255;
if(green<0)green=0;
if(blue>255) blue=255;
if(blue<0)blue=0;
Bitmap->Canvas->Pixels[i][j]=TColor(RGB(red,green,blue));
}
}
DImg->Picture->Bitmap->Assign(Bitmap);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::DiffuseClick(TObject *Sender)
{
int rx,ry;
int red,green,blue;
// SImg->Picture->Bitmap->Assign(DImg->Picture->Bitmap);//使原图像变为转化后的图像
GetRgbp(Sender);
for(i=1;i<x-3;i++)
{
for(j=1;j<y-3;j++)
{
rx=random(3);
ry=random(3);
red=rgbp[i+rx][j+ry].r;
green=rgbp[i+rx][j+ry].g;
blue=rgbp[i+rx][j+ry].b;
Bitmap->Canvas->Pixels[i][j]=TColor(RGB(red,green,blue));
}
}
DImg->Picture->Bitmap->Assign(Bitmap);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::IncertClick(TObject *Sender)
{
int red,green,blue;
//SImg->Picture->Bitmap->Assign(DImg->Picture->Bitmap);//使原图像变为转化后的图像
GetRgbp(Sender);
for(i=1;i<x-2;i++)
{
for(j=1;j<y-2;j++)
{
red=255-rgbp[i][j].r;
green=255-rgbp[i][j].g;
b