我有一些png文件,我需要在WPF (xaml)应用程序中使用矢量格式的DrawingBrush。
如何将png转换为xaml DrawingBrush?
发布于 2018-05-24 00:58:53
PNG不是矢量图形,making it one isn't something you can do by setting an attribute。您可以缩小它,但如果您尝试放大它,您将看到一些工件。无论采用哪种方式,您都不需要将其放在DrawingBrush中来进行扩展。
答案是使用ImageBrush来完成此操作
<Window.Resources>
<ImageBrush
x:Key="MyBrush"
ImageSource="SantaClaus.png"
TileMode="Tile"
Viewport="0,0,100,100"
ViewportUnits="Absolute"
Stretch="Fill"
/>
</Window.Resources>
<Grid Background="{StaticResource MyBrush}">
</Grid>

但是如果你正在处理一个设计不佳的第三方控件,它只能使用DrawingBrush,你也可以这样做:
<DrawingBrush
x:Key="MyBrush"
TileMode="Tile"
Viewport="0,0,100,100"
ViewportUnits="Absolute"
Stretch="Fill"
>
<DrawingBrush.Drawing>
<DrawingGroup>
<ImageDrawing ImageSource="SantaClaus.png" Rect="0,0,100,100" />
</DrawingGroup>
</DrawingBrush.Drawing>
</DrawingBrush>https://stackoverflow.com/questions/50492966
复制相似问题