- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试构建一个基于 Image
的自定义控件,它只是使图像在计时器上重新加载(从相同的 URI)。原始图像显示正常,但似乎没有刷新。
这里是自定义控件:
public class RefreshImage : Image
{
protected override void OnInitialized(EventArgs e)
{
base.OnInitialized(e);
this.Loaded += RefreshImage_Loaded;
}
private void RefreshImage_Loaded(object sender, RoutedEventArgs e)
{
var timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromSeconds(1);
timer.Tick += RefreshImage_Tick;
timer.Start();
}
private void RefreshImage_Tick(object sender, System.EventArgs e)
{
var bm = (BitmapImage) Source;
bm.InvalidateProperty(BitmapImage.UriSourceProperty);
}
}
我是这样使用它的:
<custom:RefreshImage>
<Image.Source>
<BitmapImage UriCachePolicy="NoCacheNoStore"
CreateOptions="IgnoreImageCache" CacheOption="None"
UriSource="{Binding Uri}"/>
</Image.Source>
</custom:RefreshImage>
InvalidateProperty 的文档似乎表明这正是我所需要的:
You can also use InvalidateProperty to force re-evaluation of a binding against a data source that is not able to implement the recommended INotifyPropertyChanged notification mechanism.
在 Uri
上引发 INotifiyPropertyChanged.PropertyChanged
事件也不会触发图像重新加载。
最佳答案
一般来说,BitmapSource
似乎是不可变对象(immutable对象)。一旦它们完成初始化,任何进一步的属性更改都将被忽略。我怀疑这包括 UriSource
。
以下阶段在 MSDN post on creating custom ImageSources
中经常重复:
The ISupportInitialize interface is used to snap the values of theproperties when initialization is complete. Further changes to theproperties are ignored.
关于wpf - 强制 WPF BitmapImage 从其 UriSource 重新加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42215967/
我有一种方法可以从 zip 文件中打开图像,并将该图像作为 BitmapImage 返回。 public BitmapImage GetImageFromSource() { using (S
这是我的代码 private async void OnGetImage(object sender, RoutedEventArgs e) { using
我正在尝试将图像的字节数组转换为 BitmapImage 以绑定(bind)到按钮。 public static BitmapImage GetBitmapImageFromByteArray(byt
我正在创建一个包含任意值的字节数组,并希望将其转换为 BitmapImage。 bi = new BitmapImage(); using (MemoryStream stream =
我可以像这样成功加载以下位图并将其显示在 View 上的图像控件中。 var bitmapImage = new BitmapImage {
我已经从文件流数据库中加载了一个图像列表。当我最初加载它们时,内存跳跃并没有那么大。当我在屏幕上显示它们时,我的内存使用量会激增,即使在我处理 BitmapImage 流源并将其设置为 Nothing
我正在开发 WP8 (Lumia 920) 的成像应用程序。我在 xaml 层中使用 C# 进行编码。 我在尝试在单独的任务中创建新的 BitmapImage 对象时遇到问题,该对象预计将使用由相机应
我有一个最初是 PNG 的图像,我已将其转换为 byte[] 并保存在数据库中。最初,我只是简单地将 PNG 读入内存流,然后将流转换为 byte[]。现在我想读回 byte[] 并将其转换为 Bit
我正在尝试将非常大的图像(大约 16000x7000 像素)加载到 Material 中,并且尝试异步加载它。我的第一个尝试是创建一个加载 BitmapImage 的任务,然后将其用于 Materia
我正在尝试从服务返回的字节数组创建一个BitmapImage。 我的代码是: using (sc = new ServiceClient()) { using (MemoryStream ms
我正在尝试将非常大的图像(大约 16000x7000 像素)加载到 Material 中,并且尝试异步加载它。我的第一个尝试是创建一个加载 BitmapImage 的任务,然后将其用于 Materia
我正在尝试从服务返回的字节数组创建一个BitmapImage。 我的代码是: using (sc = new ServiceClient()) { using (MemoryStream ms
我正在使用一个处理图像的 API,其中一种方法需要物理磁盘上文件的路径。 我遇到的问题是我通过 WCF 服务检索图像,因此图像已经存在于内存中。我不想将文件写入磁盘只是为了让此方法重新打开它并对其进行
我正在尝试在后台线程 (BackgroundWorker) 中创建一个 BitmapImage,但我的函数只立即返回 null,并且没有进入 Deployment.Current.Dispatcher
我用这段代码从网上获取图片 var image = new BitmapImage(); image.BeginInit(); image.CacheOption = BitmapCacheOptio
我试图通过每秒设置 source 属性来更新图像,这可行,但是在更新时会导致闪烁。 CurrentAlbumArt = new BitmapImage(); CurrentAlbumArt.Begin
我想旋转位图图像我写了一些代码,它可以工作 TransformedBitmap TempImage = new TransformedBitmap(); TempImage.BeginInit();
我有一组原始像素数据。我想将其转换为 8bpp 位图。 public static Bitmap ByteToGrayBitmap(byte[] rawBytes, int width, int he
我正在尝试使用以下代码将 MemoryStream 转换为 Image。 Stream stream = new MemoryStream(bytes); BitmapImage bitmap
我有一个应用程序,它从 XML 文件中读取 JPEG(到字节数组),生成 MemoryStreams 并使用它们来实例化 BitmapImages。 JPEG 的整个大小约为 60 MB。但是,我的应
我是一名优秀的程序员,十分优秀!