【发布时间】:2012-02-03 07:33:58
【问题描述】:
我想要
- 从资源中加载图片
- 设置图像宽度,确保它按比例缩放其高度。
- 将其用作背景画笔
它无法弄清楚“设置宽度”部分。
我目前使用的折衷方案是将其缩小到一半。这不是我理想中想要做的,我想将宽度设置为绝对值,不管原始图像大小是多少。
<BitmapImage x:Key="floorPlan"
UriSource="/NavigationPathEditor;component/Images/CairnsFloorPlansCropped.png"/>
<TransformedBitmap x:Key="resizedFloorPlan" Source="{StaticResource floorPlan}">
<TransformedBitmap.Transform>
<ScaleTransform
CenterX="0" CenterY="0"
ScaleX="0.5" ScaleY="0.5" />
</TransformedBitmap.Transform>
</TransformedBitmap>
<ImageBrush
x:Key="floorPlanBrush"
TileMode="None" Stretch="None"
AlignmentX="Left" AlignmentY="Top"
ImageSource="{StaticResource resizedFloorPlan}" />
(顺便说一下,上面的代码在运行时工作,但在设计器中抛出错误)
【问题讨论】:
标签: wpf xaml imagebrush