Difference between revisions of "BGRABitmap tutorial 5"
From Lazarus wiki
Jump to navigationJump to search (created) |
m (→Run the program: wiki) |
||
Line 50: | Line 50: | ||
You should see a blue sky with a moon. When you resize the form, the image is resized accordingly. | You should see a blue sky with a moon. When you resize the form, the image is resized accordingly. | ||
− | [[Image: | + | [[Image:Tutorial5a.png]] |
[[BGRABitmap tutorial 4|Previous tutorial (direct pixel access)]] | [[BGRABitmap tutorial 4|Previous tutorial (direct pixel access)]] | ||
[[Category:Graphics]] | [[Category:Graphics]] |
Revision as of 00:37, 20 March 2011
This tutorial shows you how to use layers.
Create a new project
Create a new project and add a reference to BGRABitmap, the same way as in the first tutorial.
Add a painting handler
With the object inspector, add an OnPaint handler and write : <delphi>procedure TForm1.FormPaint(Sender: TObject); var image: TBGRABitmap;
size: single;
procedure DrawMoon; var layer: TBGRABitmap; begin layer := TBGRABitmap.Create(image.Width,image.Height); layer.FillEllipseAntialias(layer.Width/2,layer.Height/2,size*0.4,size*0.4,BGRA(224,224,224,128)); layer.EraseEllipseAntialias(layer.Width/2+size*0.15,layer.Height/2,size*0.3,size*0.3,255); image.PutImage(0,0,layer,dmDrawWithTransparency); layer.Free; end;
begin
image := TBGRABitmap.Create(ClientWidth,ClientHeight);
//Compute available space in both directions if image.Height < image.Width then size := image.Height else size := image.Width;
image.GradientFill(0,0,image.Width,image.Height, BGRA(128,192,255),BGRA(0,0,255), gtLinear,PointF(0,0),PointF(0,image.Height), dmSet);
DrawMoon;
image.Draw(Canvas,0,0,True); image.free;
end; </delphi>
The procedure creates an image and fill it with a blue gradient. This is the background layer.
The procedure DrawMoon creates a layer, draw a moon in it. First a white disk is drawn, then a smaller disk is substracted. Finally, this layer is merged with the background.
Run the program
You should see a blue sky with a moon. When you resize the form, the image is resized accordingly.