WPF:使用 .ico 文件作为工具栏的图像?或者需要转换为XAML?
我知道建议将图像转换为 XAML,因为更改 dpi 时图像会变得模糊。
那么标准 ICO 文件实际上是 BMP 文件呢?
我需要在工具栏中使用它们。我需要全部转换为 XAML 吗?
有更好的办法吗?
HTML 中称为精灵的类似功能怎么样?它是一张大图像,但您可以通过位置获取项目?
I know it's recommended to convert images to XAML as they become blurred when changing the dpi.
What about standard ICO files which actually are really BMP files?
I need to use these in a toolbar. Do I need to convert all to XAML?
Is there a better way?
What about a similar feature in HTML called sprites where it's one big image but you get items via positions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
本质上,当不需要缩放时,您可以使用静态图像,而当您想要执行各种缩放时,您可以使用矢量图像。这是大多数 WPF 和 Silverlight 应用程序的经验法则。
但是,您无法直接将静态图像转换为矢量图像(即所谓的 XAML),并且大多数情况下需要设计人员对矢量图像进行一些工作。
使用矢量图像会使渲染过程变得更繁重,矢量越多,渲染过程就越慢。当您将特定的可视化树添加到屏幕上已有的内容时,它还会使实例化速度变慢。如果您调用 RenderToBitmap 并缓存要使用的矢量图像的大小,则可以克服此问题,但这需要额外的自定义代码。
使用静态图像可以加快渲染速度。然而,增大尺寸会导致像素化,而缩小尺寸可能会导致图像出现伪影。当您使用静态图像时,PNG 被认为是首选格式,您可以完全控制压缩,您有 alpha 键,并且它是一种索引格式,这使得它的大小相当小。
Essencially you work with static images when no scaling is needed, and you work with Vector Images when you want to perform all sorts of scaling. This is the rule of thumb for most WPF and Silverlight applications.
However you can't directly convert a static image to a Vector Image (what you call XAML), and most times it will require a designer to do some work on the Vector Image.
Working with vector images makes the rendering process heavier, the more vectors, the slower the rendering pass. It also makes it slower to instanciate a particular Visual Tree, when you add it to something already on screen. This can be overcome if you call RenderToBitmap and cache the sizes of the Vector Images you want to use, but this requires aditional custom code.
Working with static images allows for much faster renders. However upsizing will cause pixelization and downsizing may cause artifacts on the image. When you work with static images PNG is considered to be the prefered format, you have full control over the compression, you have alpha key and it's an indexed format which makes it fairly small in size.
我总是尽可能将所有图像转换为
XAML
。我认为这是一个很好的规则。I always convert all images to
XAML
where it's possible. I think it's good rule.