Title: Alphablending and Gradiant Fills examples
Question: How do we get all those nice blending and gradiant effects in windows. Windows 2000 and I think other versions may support it as well, now have inbuilt functions to do all the fancy stuff. The projkect source that follows demonstrates this and provides a link to my site where you can downlaod the example. (it contains bitmaps so I didn't think you would want me to past the DFM as text !)
Answer:
The source for this is at http://www.lummie.co.uk/delphi/APIGradiant and AlphaBlend Examples.zip
First on the onpaint of the form I show how to do a gradiant from blue to white - notice you can set teh
procedure TForm1.FormPaint(Sender: TObject);
var
udtVertex: array [0..1] of _TRIVERTEX;
rectGradient: TGradientRect;
begin
with udtVertex[0] do
begin
x := 0;
y := height;
Red := 0;
Green := 0;
Blue := $ff00;
Alpha := $5500;
end;
with udtVertex[1] do
begin
x := Width;
y := 0;
Red := $ff00;
Green := $ff00;
Blue := $ff00;
Alpha := $5500;
end;
rectGradient.UpperLeft := 0;
rectGradient.LowerRight := 1;
GradientFill(Canvas.Handle,
@udtVertex, 2,
@rectGradient, 1,
GRADIENT_FILL_RECT_H);
end;
for more information look on MSDN.microsoft.com and search for gradiantfill
Button1Click shows the simple alphablending of two images.
procedure TForm1.Button1Click(Sender: TObject);
var
res : TBitmap;
bf : _BLENDFUNCTION;
begin
res := TBitmap.create;
try
res.width := i1.picture.width;
res.height := i1.picture.height;
res.assign(i1.picture.bitmap);
bf.BlendOp := AC_SRC_OVER;
bf.BlendFlags := 0;
bf.SourceConstantAlpha := BlendAmount.Value;
bf.AlphaFormat := 0;
AlphaBlend(res.canvas.handle, 0,0,res.width,res.height,i2.picture.bitmap.Canvas.handle,0,0,res.width,res.height,bf);
i3.Picture.assign(res);
finally
res.free;
end;
end;
Have fun......