I've not really worked with graphics before, but I need to design a screen saver that animates, ie. moves a company logo around the screen, bouncing off the sides.
So far, using GDIPLUS, I do the following ...
Image1: IGPImage;
Image2: IGPImage;
Image1 := TGPImage.Create('background.png');
Image2 := TGPImage.Create('logo.png');
and draw it as follows, in the OnPaint
event of a TPaintBox
. A TTimer
component provides the event to Invalidate
the TPaintBox
.
procedure TFormMain.PaintBox1Paint(Sender: TObject);
var
GPGraphics: IGPGraphics;
i: integer;
begin
GPGraphics := TGPGraphics.Create(PaintBox1.Canvas.Handle);
//Restore the background
GPGraphics.DrawImage(Image1, 0, 0);
// Determine the next position of the logo
// We will also determine here if we are at the edges (not shown)
X := X + 1;
Y := Y + 1;
// Draw the logo somewhere on the screen
GPGraphics.DrawImage(Image2, X, Y);
end;
The result however is not completely satisfactory as the logo flickers a bit and the movement across the screen (1680x1050 pixels, 32 bit colour)
, takes forever to reach any sides. I have no idea how to speed it up whilst retaining a smooth transition of the logo across the screen.
I currently use Delphi XE on Windows XP.