|
void __fastcall DrawClientWindow (HDC &Hdc)
{
// this routine paints a gradient background that slowly
// changes from StartColor at the top to black at the bottom
const int NumGradients = 64; // number of shading levels
const TColor StartColor = clBlue; // initial color
TRect rect ; // calculate size of backgnd
::GetClientRect (Form1->Handle, (RECT *) &rect) ;
// painting a shaded gradient is slow, and can cause flickering
// eliminate flicker by using memory bitmaps and BitBlit
Graphics::TBitmap *MemBitmap = new Graphics::TBitmap;
MemBitmap->Width = rect.Right - rect.Left;
MemBitmap->Height= rect.Bottom- rect.Top;
MemBitmap->Canvas->Brush->Style = bsSolid;
MemBitmap->Canvas->Brush->Color = clBlack;
MemBitmap->Canvas->FillRect(Rect(0,0,
MemBitmap->Width,
MemBitmap->Height));
// calculate the height of each little gradient section
int GradientHeight = MemBitmap->Height / NumGradients;
// calculate individual RGB intensities of the starting color.
int InitialRed = GetRValue(StartColor);
int InitialGreen = GetGValue(StartColor);
int InitialBlue = GetBValue(StartColor);
int RedIncrement = (InitialRed + 1) / NumGradients; // calculate
int GreenIncrement= (InitialGreen + 1)/ NumGradients; // increment of
int BlueIncrement = (InitialBlue + 1) / NumGradients; // each gradient
TColor FillColor;
// the for loop draws each gradient section. the loop stops one pass
// away from black because black was drawn by FillRect above
for (int j=0;j< NumGradients;j++)
{
rect.Bottom = rect.Top + GradientHeight;
FillColor = (TColor) RGB( InitialRed -(RedIncrement * j),
InitialGreen -(GreenIncrement* j),
InitialBlue -(BlueIncrement * j));
MemBitmap->Canvas->Brush->Color = FillColor;
MemBitmap->Canvas->FillRect(rect);
rect.Top += GradientHeight;
}
// Use API BitBlt to copy pixels to the screen.
::BitBlt(Hdc,0,0,MemBitmap->Width, MemBitmap->Height,
MemBitmap->Canvas->Handle,0,0,SRCCOPY);
delete MemBitmap; // delete the temporary bitmap.
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
DrawClientWindow(Canvas->Handle);
}
<출처를알수없음>
박용우 님이 쓰신 글 :
: 그라데이션 효과 아시죠..
: 점점 진해진다든지 점점 밝아지는 그런 효과를 주려고하는데
: 어떻게 하시는지 아시는분
: 캔버스에 사각형을 그리고 싶어요 입체감있게 보이는.
|