图像整合
问题描述:
我已经使用路径创建自定义对象为:图像整合
<Path Style="{StaticResource ABC_Style}" ToolTip="object ABC" HorizontalAlignment="Center" VerticalAlignment="Center"></Path>
ABC_Style定义是:
<Style x:Key="ABC_Style" TargetType="Path">
<Setter ..../>
<Setter Property="Fill" Value .../>
</Style>
现在,我必须的网眼图像分配到对象(如内容)。
问题:
- 有什么办法将图像整合到它?
- 如果是这样,是否有可能避免图片被拉伸?
谢谢。
答
我能想到的是,你可以创建一个画刷类似
<ImageBrush ImageSource="image.jpg" x:Key="imageBrush" />
<DrawingBrush x:Key="ThatchBackground" Viewport="0,0,50,50" ViewportUnits="Absolute" Stretch="None" TileMode="Tile">
<DrawingBrush.Drawing>
<GeometryDrawing Brush="{StaticResource imageBrush}">
<GeometryDrawing.Geometry>
<GeometryGroup>
<RectangleGeometry Rect="0,0,50,50"/>
</GeometryGroup>
</GeometryDrawing.Geometry>
</GeometryDrawing>
</DrawingBrush.Drawing>
</DrawingBrush>
,并设置路径填补像下面
<Path Fill="{StaticResource ThatchBackground}">
我得到这个从本教程http://wpfplayground.blogspot.com/2011/09/texture-background-in-wpf.html
+1
DrawingBrush完全没有必要。只需在ImageBrush中设置Viewport =“0,0,50,50”,“ViewportUnits =”Absolute“','Stretch =”Fill“'和'TileMode =”Tile“'并将其用作Fill:''。这是可能的,因为ImageBrush也是一个TileBrush。 – Clemens
见这[相关问题](http://stackoverflow.com/q/9670109/620360)。 – LPL
你是不是想用图像填充路径,即用'ImageBrush'设置'Fill'属性? – Clemens