如何调整图片的饱和度?

时间:2021-08-28 20:31:58
我已将黑白图片进行了上色,即使其有单一的色调:

//代码如下:
void __fastcall TfrmPicEdit::TrackBar1Change(TObject *Sender)
{
  int red,green,blue;
  for(i=0;i< width-2;i++)
    for(j=0;j< height-2;j++)
    {
      red=abs(rgb[i][j].r_color+TrackBar1->Position);
      green=abs(rgb[i][j].g_color+TrackBar2->Position);
      blue=abs(rgb[i][j].b_color+TrackBar3->Position);
      bitmap->Canvas->Pixels[i][j]=TColor(RGB(red,green,blue));
    }
  Image1->Picture->Bitmap->Assign(bitmap);

}
//---------------------------------------------------------------------------

如何调整当前色调的饱和度?

4 个解决方案

#1


// 调节饱和度
// 算法:
// 参数: sBmp 源图,dBmp 目的图,Amount 系数
// Amount 0~510
void __fastcall TForm1::Saturation(Graphics::TBitmap* sBmp,Graphics::TBitmap* dBmp,int Amount)
{
  int Grays[768];
  Word Alpha[256];
  int Gray,x,y,ag;
  RGBTRIPLE* psRGB;
  RGBTRIPLE* pdRGB;
  x=0,y=0;
  for(ag=0;ag<=85;ag++)
  {
    Grays[x+0]=y;
    Grays[x+1]=y;
    Grays[x+2]=y;
    y++;
    x+=3;
  }
  for(x=0;x<=255;x++)
    Alpha[x]=(x*Amount)>>8;
  for(y=0;y<=sBmp->Height-1;y++)
  {
    psRGB=(RGBTRIPLE*)sBmp->ScanLine[y];
    pdRGB=(RGBTRIPLE*)dBmp->ScanLine[y];
    for(x=0;x<=sBmp->Width-1;x++)
    {
      Gray=Grays[psRGB->rgbtRed]+Grays[psRGB->rgbtGreen]+Grays[psRGB->rgbtBlue];
      ag=Alpha[Gray];
      pdRGB->rgbtBlue =IntToByte(Gray+(Alpha[psRGB->rgbtBlue]-ag));
      pdRGB->rgbtGreen=IntToByte(Gray+(Alpha[psRGB->rgbtGreen]-ag));
      pdRGB->rgbtRed=IntToByte(Gray+(Alpha[psRGB->rgbtRed]-ag));
      psRGB++;
      pdRGB++;
    }
  }
}

#2


学习

#3


UP!

#4


好啊。学习

#1


// 调节饱和度
// 算法:
// 参数: sBmp 源图,dBmp 目的图,Amount 系数
// Amount 0~510
void __fastcall TForm1::Saturation(Graphics::TBitmap* sBmp,Graphics::TBitmap* dBmp,int Amount)
{
  int Grays[768];
  Word Alpha[256];
  int Gray,x,y,ag;
  RGBTRIPLE* psRGB;
  RGBTRIPLE* pdRGB;
  x=0,y=0;
  for(ag=0;ag<=85;ag++)
  {
    Grays[x+0]=y;
    Grays[x+1]=y;
    Grays[x+2]=y;
    y++;
    x+=3;
  }
  for(x=0;x<=255;x++)
    Alpha[x]=(x*Amount)>>8;
  for(y=0;y<=sBmp->Height-1;y++)
  {
    psRGB=(RGBTRIPLE*)sBmp->ScanLine[y];
    pdRGB=(RGBTRIPLE*)dBmp->ScanLine[y];
    for(x=0;x<=sBmp->Width-1;x++)
    {
      Gray=Grays[psRGB->rgbtRed]+Grays[psRGB->rgbtGreen]+Grays[psRGB->rgbtBlue];
      ag=Alpha[Gray];
      pdRGB->rgbtBlue =IntToByte(Gray+(Alpha[psRGB->rgbtBlue]-ag));
      pdRGB->rgbtGreen=IntToByte(Gray+(Alpha[psRGB->rgbtGreen]-ag));
      pdRGB->rgbtRed=IntToByte(Gray+(Alpha[psRGB->rgbtRed]-ag));
      psRGB++;
      pdRGB++;
    }
  }
}

#2


学习

#3


UP!

#4


好啊。学习