【发布时间】:2017-04-05 05:21:13
【问题描述】:
我想经常从内存中更新页面中的图像。我已经测试过直接从资源(闪烁)和预加载流(闪烁)加载它。这是我的 xaml:
<Image Source="{Binding Image}" VerticalOptions="Center" HorizontalOptions="FillAndExpand"/>
这是我的视图模型:
this.loaderTask = new Task(() =>
{
int i = 0;
while (true)
{
await Task.Delay(1000);
if (i++ % 2 == 0)
this.Image = ImageSource.FromStream(() => new MemoryStream(this.buf1));
else
this.Image = ImageSource.FromStream(() => new MemoryStream(this.buf2));
Xamarin.Forms.Device.BeginInvokeOnMainThread(() =>
{
this.OnPropertyChanged(nameof(this.Image));
});
}
});
在 Android 上测试。我想有一些“标准”的方法可以做到这一点?
编辑:闪烁是指您很快就会看到图像消失,然后绘制新图像。我希望一个快速的解决方案是将占位符放在与我要更新的位置相同的位置,但这也无济于事,在加载过程中仍会获得默认的白色背景。
【问题讨论】:
-
使用动画在它们之间转换?