以下是c++代码,改成Delphi的应该很容易的
void Form1:
oContrast(int s)//调整对比度
{
int XX;
BYTE *ptr;
Graphics::TBitmap *tmpBitmap=new Graphics::TBitmap();
tmpBitmap->Assign((TPersistent*)Image->Picture->Graphic);
tmpBitmap->PixelFormat=pf24bit;
for (int y = 0; y < tmpBitmap->Height; y++)
{
ptr =(BYTE *) tmpBitmap->ScanLine[y];
for (int x = 0; x < tmpBitmap->Width*3; x+=3){
XX=((ptr[x+2]-128)*s+12800)/100;
XX=MAX(XX,0);XX=MIN(XX,255);ptr[x+2]=XX;
XX=((ptr[x+1]-128)*s+12800)/100;
XX=MAX(XX,0);XX=MIN(XX,255);ptr[x+1]=XX;
XX=((ptr[x]-128)*s+12800)/100;
XX=MAX(XX,0);XX=MIN(XX,255);ptr[x+0]=XX;
}
}
Image->Picture->Graphic=tmpBitmap;
delete tmpBitmap;
}
//---------------------------------------------------------------------------
void TMainForm:
oBright(int b)//调整亮度
{
int XX;
BYTE *ptr;
Graphics::TBitmap *tmpBitmap=new Graphics::TBitmap();
tmpBitmap->Assign((TPersistent*)Image->Picture->Graphic);
tmpBitmap->PixelFormat=pf24bit;
for (int y = 0; y < tmpBitmap->Height; y++)
{
ptr =(BYTE *) tmpBitmap->ScanLine[y];
for (int x = 0; x < tmpBitmap->Width*3; x+=3){
XX=ptr[x+2]+b;
XX=MAX(XX,0);XX=MIN(XX,255);ptr[x+2]=XX;
XX=ptr[x+1]+b;
XX=MAX(XX,0);XX=MIN(XX,255);ptr[x+1]=XX;
XX=ptr[x]+b;
XX=MAX(XX,0);XX=MIN(XX,255);ptr[x+0]=XX;
}
}
Image->Picture->Graphic=tmpBitmap;
delete tmpBitmap;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::N12Click(TObject *Sender)//调整色彩平衡
{
int XX;
BYTE *ptr;
Graphics::TBitmap *tmpBitmap=new Graphics::TBitmap();
tmpBitmap->Assign((TPersistent*)Image->Picture->Graphic);
tmpBitmap->PixelFormat=pf24bit;
Form2->TrackBar1->Position=0;
Form2->TrackBar2->Position=0;
Form2->TrackBar3->Position=0;
if (Form->ShowModal()==IDOK){
for (int y = 0; y < tmpBitmap->Height; y++)
{
ptr =(BYTE *) tmpBitmap->ScanLine[y];
for (int x = 0; x < tmpBitmap->Width*3; x+=3){
XX=ptr[x+2]+CForm->TrackBar1->Position;
XX=MAX(XX,0);XX=MIN(XX,255);ptr[x+2]=XX;
XX=ptr[x+1]+CForm->TrackBar2->Position;
XX=MAX(XX,0);XX=MIN(XX,255);ptr[x+1]=XX;
XX=ptr[x]+CForm->TrackBar3->Position;
XX=MAX(XX,0);XX=MIN(XX,255);ptr[x+0]=XX;
}
}
Image->Picture->Graphic=tmpBitmap;
}
delete tmpBitmap;
}
//---------------------------------------------------------------------------
void __fastcall Form1::BlurButtonClick(TObject *Sender)//模糊效果,也应该是柔化吧
{
int flt[9];
flt[0]=5;flt[1]=5;flt[2]=5;
flt[3]=5;flt[4]=60;flt[5]=5;
flt[6]=5;flt[7]=5;flt[8]=5;
DoFilter(flt,100);
}
//---------------------------------------------------------------------------
void Form1:
oFilter(int * flt, int Div)
{
int XX[3];
BYTE *ptr,*ptru,*ptrd,*ptr1;
Graphics::TBitmap *Bitmap=new Graphics::TBitmap();
Graphics::TBitmap *tmpBitmap=new Graphics::TBitmap();
Bitmap->Assign((TPersistent*)Image->Picture->Graphic);
Bitmap->PixelFormat=pf24bit;
tmpBitmap->Assign((TPersistent*)Image->Picture->Graphic);
tmpBitmap->PixelFormat=pf24bit;
for (int y = 1; y < tmpBitmap->Height-1; y++)
{
ptr=(BYTE *)Bitmap->ScanLine[y];
ptr1=(BYTE *)tmpBitmap->ScanLine[y];
ptru=(BYTE *)tmpBitmap->ScanLine[y-1];
ptrd=(BYTE *)tmpBitmap->ScanLine[y+1];
for (int x=3;x<(tmpBitmap->Width-1)*3;x+=3){
XX[0]=0;XX[1]=0;XX[2]=0;
for (int i=-1;i<=1;i++)
for (int j=0;j<3;j++)
XX[j]+=ptr1[x+3*i+j]*flt[4+i];
for (int i=-1;i<=1;i++)
for (int j=0;j<3;j++)
XX[j]+=ptru[x+3*i+j]*flt[1+i];
for (int i=-1;i<=1;i++)
for (int j=0;j<3;j++)
XX[j]+=ptrd[x+3*i+j]*flt[7+i];
for (int i=0;i<3;i++){
XX
=XX/Div;
XX=MAX(XX,0);
XX=MIN(XX,255);
ptr[x+i]=XX;
}
}
}
Image->Picture->Graphic=Bitmap;
delete tmpBitmap;
delete Bitmap;
}
void __fastcall Form1::SharpButtonClick(TObject *Sender)//锐化效果处理
{
int flt[9];
flt[0]=0;flt[1]=-5;flt[2]=0;
flt[3]=-5;flt[4]=30;flt[5]=-5;
flt[6]=0;flt[7]=-5;flt[8]=0;
DoFilter(flt,10);
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::EnchaseButtonClick(TObject *Sender)//雕刻效果处理
{
int flt[9];
flt[0]=-15;flt[1]=-15;flt[2]=0;
flt[3]=-15;flt[4]=15;flt[5]=15;
flt[6]=0;flt[7]=15;flt[8]=0;
DoFilter(flt,10);
}
//---------------------------------------------------------------------------
void __fastcall TMainForm:1Click(TObject *Sender)
{
float AspectRatio,OutputWidth, OutputHeight;
if (!PrintDialog1->Execute()) return;
Printer()->BeginDoc();
OutputWidth = Image->Picture->Width;
OutputHeight = Image->Picture->Height;
AspectRatio = OutputWidth / OutputHeight;
if (OutputWidth < Printer()->PageWidth&&OutputHeight < Printer() ->PageHeight){
if (OutputWidth < OutputHeight){
OutputHeight = Printer()->PageHeight;
OutputWidth = OutputHeight * AspectRatio;
}
else{
OutputWidth = Printer()->PageWidth;
OutputHeight = OutputWidth / AspectRatio;
}
}
if (OutputWidth > Printer()->PageWidth){
OutputWidth = Printer()->PageWidth;
OutputHeight= OutputWidth / AspectRatio;
}
if (OutputHeight > Printer()->PageHeight){
OutputHeight = Printer()->PageHeight;
OutputWidth = OutputHeight * AspectRatio;
}
Printer()->Canvas->StretchDraw(Rect(0,0,
floor(OutputWidth), floor(OutputHeight)),
Image->Picture->Graphic);
}
//---------------------------------------------------------------------------