📄 unit1.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include <math.h>
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
if(OpenPictureDialog1->Execute())
{
Image1->Picture->LoadFromFile(OpenPictureDialog1->FileName);
width=Image1->Picture->Width;
height=Image1->Picture->Height;
//读入位图各象素点图像的RGB值
int i,j;
rgb=new RGBColor*[width];
TColor color;
for(i=0;i<width;i++)
{
rgb[i]=new RGBColor[height];
for(j=0;j<height;j++)
{
color=Image1->Canvas->Pixels[i][j];
rgb[i][j].r=GetRValue(color);
rgb[i][j].g=GetGValue(color);
rgb[i][j].b=GetBValue(color);
}
}
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
Graphics::TBitmap* myBitmap;
myBitmap=new Graphics::TBitmap;
myBitmap->Width=width;
myBitmap->Height=height;
int red,green,blue;
int i,j;
for(i=0;i<width;i++)
for(j=0;j<height;j++)
{
if(i==0||j==0)
{
red=64;
green=64;
blue=64;
}
else
{
red=abs(rgb[i][j].r-rgb[i-1][j-1].r)+64;
green=abs(rgb[i][j].g-rgb[i-1][j-1].g)+64;
blue=abs(rgb[i][j].b-rgb[i-1][j-1].b)+64;
}
myBitmap->Canvas->Pixels[i][j]=TColor(RGB(red,green,blue));
}
Image2->Picture->Bitmap->Assign(myBitmap);
delete myBitmap;
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -