Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Image 在屏幕上移动图像,从边缘反弹_Image_Delphi_Screensaver - Fatal编程技术网

Image 在屏幕上移动图像,从边缘反弹

Image 在屏幕上移动图像,从边缘反弹,image,delphi,screensaver,Image,Delphi,Screensaver,我以前没有真正使用过图形,但我需要设计一个屏幕保护程序,使其具有动画效果,即在屏幕上移动公司徽标,使其从侧面反弹 到目前为止,使用GDIPLUS,我做了以下工作 Image1: IGPImage; Image2: IGPImage; Image1 := TGPImage.Create('background.png'); Image2 := TGPImage.Create('logo.png'); 并在TPaintBox的OnPaint事件中按如下方式绘制。TTimer组件提供使TPain

我以前没有真正使用过图形,但我需要设计一个屏幕保护程序,使其具有动画效果,即在屏幕上移动公司徽标,使其从侧面反弹

到目前为止,使用GDIPLUS,我做了以下工作

Image1: IGPImage; 
Image2: IGPImage;

Image1 := TGPImage.Create('background.png');
Image2 := TGPImage.Create('logo.png');
并在TPaintBox的OnPaint事件中按如下方式绘制。TTimer组件提供使TPaintBox无效的事件

然而,结果并不完全令人满意,因为徽标有点闪烁,屏幕上的移动1680x1050像素,32位颜色,需要永远到达任何一侧。我不知道如何加快速度,同时在屏幕上保持徽标的平滑过渡


我目前在Windows XP上使用Delphi XE。

我知道这是一个老问题,但它值得回答

为了避免GDI+和其他许多图形系统一样闪烁,您需要将整个图像爆破到屏幕上

在您的例子中,这意味着您必须创建一个具有屏幕大小的位图,为该位图绘制背景,然后为该位图绘制您喜欢的任何图像,最后在屏幕上绘制位图。这根本不会弹


当然,位图只需要创建一次,并且可以随意重用。OnPaint将绘制该位图。在其他地方,你的定时器程序,你画进位图,然后你使窗口无效,这反过来会触发OnPaint事件。

一些示例:,等等。当然,对于更高级/平滑的图形,你需要放弃GDI,看看OpenGL或Direct X。无论如何,不要使用TPaintBox。直接画到表格上!而且,如果你只想画一个PNG图像,你不需要使用GDI+。由纯GDI渲染的TPngImage就足够了。当然,第一条评论中的建议仍然适用。对于平滑的全屏动画,GDI或GDI+是不够的。Andreas,谢谢你的例子。我肯定会使用部分或全部。我肯定也会看看OpenGL和Direct-X。我可能会学到一些东西!自定义屏幕保护程序非常有用。如今,大多数默认电源方案在一段时间后完全关闭显示器,以节省能耗。
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;