C#: Creating a graphical screensaver

2019-04-15 20:57发布

I am thinking about creating a screen saver. I have the whole thing, its graphics and the back-end kind of ready in my head. But I am not quite sure how to get the graphics out in code.

What I would like is a slide show of images with a bit of movement (kind of like the slide show in media center) and some floating text and shapes on top. The shapes somehow translucent.

I currently have a very simple static slideshow made in WinForms. Just a simple application that goes fullscreen and displays some images and pretends to fade them in and out in a hackish kind of way. But it is not very well made, and the performance is not very good. For example to prevent lag, I fade in a black square on top of the image, instead of fading in the actual image. Silly perhaps, but it kind of worked :p

Anyways, I would like to do a better job. But not sure where to start. Is WPF a good solution for this? Or should I look into DirectX or OpenGL? Is this something that could be handled well with XNA, or is that too game spesific?

6条回答
萌系小妹纸
2楼-- · 2019-04-15 21:05

A few weeks ago I wrote a two-part article describing how to create a Windows screen saver with GDI+. I am not displaying a slide show in my screen saver, but instead I am randomly drawing shapes. I did however explain the fundamentals of creating a screen saver for Windows which should be of some help if you have never created a screen saver before.

查看更多
神经病院院长
3楼-- · 2019-04-15 21:08

Recently I finished with my first WPF (I wanted to see, how it can be done with WPF) screen-saver. You can check-it out on YouTube. Try to see HD-version.

Though I never tried XNA, I'm really pleased with WPF so far. Easy and flexible. But I guess you probably wouldn't get an XNA-performance (or am I wrong here?).

You can google for GDI+ or WPF ScreenSaver-templates to start with.

查看更多
对你真心纯属浪费
4楼-- · 2019-04-15 21:10

Actually XNA works pretty well. For example: this is an (advanced) example of what can be made with XNA. The community is quite helpful and XNA has great potential.

查看更多
何必那么认真
5楼-- · 2019-04-15 21:13

I guess XNA works well. There's a sample screensaver in C# Express, by the way.

查看更多
女痞
6楼-- · 2019-04-15 21:18

If you want to go with just GDI and GDI+, I wrote some info here about how to speed them up when rendering images and drawing them to screen. There is also fully functional screen saver source code at the above link (which I wrote myself after digging for some of the more obscure screen saver details), in case that helps.

查看更多
叼着烟拽天下
7楼-- · 2019-04-15 21:23

WPF is not a bad idea. It takes advantage of DirectX and hardware acceleration for its animations and effects.

You will get better performance if you write this kind of stuff natively (against directx or opengl), but the cost of writing it will be much higher. It's quite possible you will not need that edge anyway.

Have a look at hanselman's baby smash (which is a full screen wpf app with animations) to get a grasp of what you can do with wpf.

Note: I did write a slide show kind of thingy in WPF way back, the key to getting this to work smoothly is loading up the images in a background thread and freezing it.

查看更多
登录 后发表回答