Please post bug reports, feature requests, or any question regarding the DELPHI AREA projects here.

Hi guys,
your TGradient is really cool, but it misses a function I think, the ability so save the actual bitmap of the gradient.
Is there any way to get it? Personally I tried a CopyRect, but it has a lot of problems.

Thank you
Christian Cristofori

zizzo81
Member

Posts: 3
Joined: October 22nd, 2009, 6:28 am
Location: Italy

Re: Save a TGradient to TBitmap

There is a protected property named Pattern that holds the gradient bitmap.

Code: Select all
TGradientHack = class(TGradient);Image1.Picture.Assign(TGradientHack(Gradient1).Pattern);
Kambiz

Kambiz

Posts: 2430
Joined: March 7th, 2003, 7:10 pm

Re: Save a TGradient to TBitmap

Thnk you, but all it gives me out is a single line bitmap (i'm using gsDiagonalLF as Style), if I try a radial one it gives me a square.

My goal is to make a big TGradient (for example 1024 x 768), to save it to a bitmap file, then set it as my desktop wallpaper... and I can't get this out even with your *hack* solution.

Thank you again
Christian

zizzo81
Member

Posts: 3
Joined: October 22nd, 2009, 6:28 am
Location: Italy

Re: Save a TGradient to TBitmap

Actually there is no need to hack TGradient to get pattern. The CopyPatternTo method pt TGradient copies pattern in to a bitmap.

What you need is to stretch draw the pattern on your own bitmap. Do not pay attention to dimension of the pattern. The pattern's dimension is the minimum dimension required to hold the pattern information for 256 color level, and it depends on the selected gradient style.

Code: Select all
procedure TForm1.Button1Click(Sender: TObject);var  Pattern: TBitmap;  Rect: TRect;begin  Pattern := TBitmap.Create;  try    Gradient1.CopyPatternTo(Pattern);    SetRect(Rect, 0, 0, MyBitmap.Width, MyBitmap.Height);    MyBitmap.Canvas.StretchDraw(Rect, Pattern);  finally    Pattern.Free;  end;end;
Kambiz

Kambiz

Posts: 2430
Joined: March 7th, 2003, 7:10 pm

Who is online

Users browsing this forum: Bing [Bot] and 4 guests