简体   繁体   English

WPF中2d图形优于2d图像的优点和缺点

[英]2d Graphics advantages & disadvantages over 2d Images in WPF

I need to know whether there is any advantages or disadvantages on using 2d graphics in wpf over 2d images or not? 我需要知道在wpf中使用2d图形而不是2d图像有什么优点或缺点吗?

I mean if I'm going to display an ellipse in a wpf window which one is more useful and why? 我的意思是,如果我要在wpf窗口中显示一个椭圆,哪个更有用,为什么? To create an Ellipse object or to create an Image control and then load an pre-designed ellipse image into it? 要创建一个Ellipse对象还是要创建一个Image控件,然后将一个预先设计的椭圆图像加载到其中?

Does using 2D graphics have any advantages in the sense that they consume less memory or increase performance or anything like that? 使用2D图形是否在减少内存消耗或提高性能等方面具有任何优势?

Thanks in advance. 提前致谢。

An Image is not realy good scalable. 图像并不是很好的可伸缩性。

An vector Graphics is. 矢量图形是。

On a high dpi display your Image with Width = 300 (Units not pixels) and Height = 300 (units) is on a Display with 96 dpi not bigger than a Display with 144dpi. 在高dpi显示器上,宽度为300(单位不是像素)且高度为300(单位)的图像位于96 dpi的显示器上,而不大于144dpi的显示器。 But the Image on the 144 dpi display needs more Pixels for the same size. 但是,相同尺寸的144 dpi显示器上的图像需要更多像素。

1 Unit is 1/96 inch. 1个单位是1/96英寸。

So it is better to have a scalable "image" than a fixed one. 因此,拥有可伸缩的“图像”比固定图像更好。

Its one of the features of wpf that winform don't have! Winform没有的WPF功能之一! and the reason why you should not use Pixels as a Size / Width / Height / Position / etc. 以及为什么不应将像素用作尺寸/宽度/高度/位置/等的原因

Excursus: 附录:

In winform it is hard to programm a scalable programm. 在winform中,很难对可扩展程序进行编程。 on high dpi monitors the font, buttons etc. looks very small. 在高dpi显示器上,字体,按钮等看起来很小。 there was no option to solve this problem. 没有解决这个问题的选择。 so windows programmed an algorithm that creates a bitmap of the programm and scales this up. 因此Windows编写了一种算法,该算法可创建程序的位图并对其进行放大。 So: the progamms width and height is the same as before, but the user sees a much bigger one (the Bitmap). 因此:程序的宽度和高度与以前相同,但是用户看到了一个更大的程序(位图)。 The user input is then recalculated on the real sized application; 然后,在实际大小的应用程序上重新计算用户输入; Everything is working fine - and looking fine. 一切正常-看起来不错。

Hope that helps and is correct. 希望有帮助并且正确。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM