在我的应用程序中动态加载图像时遇到一个大问题。当我启动应用程序时,占位符图像源为空。当我单击按钮时,将创建图像并将其作为占位符源加载。当我再次单击时,会创建一个新图像,但会显示旧图像。图像的创建非常完美。我磁盘上的文件是它们应该的文件。
下面的函数是设置图片占位符的来源。
public void setImage(string path)
{
BitmapImage img = new BitmapImage();
img.BeginInit();
img.UriSource = new Uri(path, UriKind.Relative);
img.EndInit();
//Set Refreshing Options
img.CacheOption = BitmapCacheOption.None;
img.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
placeholder.Source = img;
}
BitmapCacheOption 和 BitmapCreateOptions 这两个选项不会改变任何内容。
你们有人可以帮助我吗?
您可能需要创建一个 WebRequest 并手动下载图像,而不是依赖 Image 类来为您完成此操作。
另一种选择是以一种简单的方式更改 Uri,使其独一无二。例如,您可以附加 GUID 作为查询字符串。