📄 unit1.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.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;
int dx,dy;
for(i=0;i<width;i++)
for(j=0;j<height;j++)
{
if(i==0||i==width-1||j==0||j==height-1)
{
red=rgb[i][j].r;
green=rgb[i][j].g;
blue=rgb[i][j].b;
}
else
{
dx=random(3);
dy=random(3);
red=rgb[i-1+dx][j-1+dy].r;
green=rgb[i-1+dx][j-1+dy].g;
blue=rgb[i-1+dx][j-1+dy].b;
}
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 + -