【发布时间】:2016-10-08 01:54:19
【问题描述】:
如何更改运行时显示的图像?
我的代码如下:
<Image Stretch="Uniform" HorizontalAlignment="Center" VerticalAlignment="Center">
<Image.Source>
<BitmapImage x:Name="Profile"
DecodePixelWidth="300"
DecodePixelHeight="300"
UriSource="/MyAssembly;component/Resources/Profile1.png" />
</Image.Source>
</Image>
我要使用的图像基本上是线条艺术,因此由于像素调整,直接使用 Image 元素创建这种缩略图是不行的。
我需要更改显示的图像,但更改UriSource 似乎没有任何作用,如果我使用图像的来源,它似乎要求我取消整个 Image.Source 部分。
【问题讨论】:
-
如何以编程方式更改
UriSource?你能展示你不断变化的 C# 代码吗? -
我发现我实际上可以将 BitmapImage 传递给 Image 元素的 Source。
-
public ImageSource FileToImageSource(Uri File, int DecodeSize = 300) { BitmapImage bitmap = new BitmapImage(File); bitmap.DecodePixelWidth = 解码大小;位图。冻结();返回位图; }