WPF Images vs. XAML

萝らか妹 提交于 2019-12-22 06:58:36

问题


When should we use images (jpg, png) and when should we use XAML in an application.

Image

+ "easy" for the designer to create what he wants
+ are displayed the same on every computer
- fixed resolution

XAML

+ vector format (resolution independent, resize able, ...)
+ can be animated
+/- rendered by the client
- not as many effects available as for images or are really complex to create
- complex visual tree

I could not find any source, that compares the resource usage (CPU, RAM) between images and XAML.

I personally think everything should be XAML, but I don't want to have an application that is slow as hell. Are there any good performance guidelines for using XAML drawings?


Researching this I've read that you should have everything in XAML and then use RenderTargetBitmap to create static images on demand, but according to this article it will cause the window to be rendered without hardware acceleration. So I'm wondering if it is really an improvement for performance. Ignoring the fact that it is much more work for the coder.


回答1:


From your comment:-

I am only talking about the cases where image and xaml is interchangeable

Use a PNG, period. Only use Xaml based imagery when you actually need the advantages it provides. There may be some edge case exceptions, for example, a large image that can be composed from a couple of simple paths in Xaml. However you would also have to have a good reason to believe that any performance difference is appreciable and worth eliminating. Ultimately favor simplicity over complexity when the same results are achievable from both.




回答2:


If your artist/designer can create vector graphics and there are no complex gradients, then I would prefer vector graphics. You get all advantages and no disadvantages.

And if you are concerned about complex visual trees, then WPF offers bitmap caching specifically for these kind of cases.



来源:https://stackoverflow.com/questions/6290928/wpf-images-vs-xaml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!