由于图像闪烁,我使用了WriteableBitmap。我有3个缩放因子的图像。但 GetFileFromApplicationUriAsync 始终会读取具有最高缩放系数的图像,并且移动设备上的图像太大。 这是我的代码:
private async Task<WriteableBitmap> CreateBitmapImage(Uri uri)
{
var file = await StorageFile.GetFileFromApplicationUriAsync(uri);
BitmapImage bitmapImage;
WriteableBitmap writeableBitmap;
using (IRandomAccessStream fileStream = await file.OpenAsync(FileAccessMode.Read))
{
bitmapImage = new BitmapImage();
await bitmapImage.SetSourceAsync(fileStream);
writeableBitmap = new WriteableBitmap(bitmapImage.PixelHeight, bitmapImage.PixelWidth);
fileStream.Seek(0);
await writeableBitmap.SetSourceAsync(fileStream);
}
return writeableBitmap;
}
我使用BitmapImage,因为WriteableBitmap需要像素高度和宽度作为构造函数中的输入参数。 Uri例如:ms-appx:///Images/contact.png
答案 0 :(得分:1)
我用这种方式解决了这个问题:
<Image Grid.Column="0" x:Name="StatusImage" Margin="0,8,12,8" Source="{x:Bind ImageStatusUri, Mode=OneWay}">
<interactivity:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="ImageOpened">
<core:ChangePropertyAction PropertyName="Source" Value="{Binding ElementName=StatusImage, Path=Source}" TargetObject="{Binding ElementName=CopyOfStatusImage}"/>
</core:EventTriggerBehavior>
</interactivity:Interaction.Behaviors>
</Image>
<Image Grid.Column="0" Margin="0,8,12,8" x:Name="CopyOfStatusImage"/>
所以我不需要使用WriteableBitmap和GetFileFromApplicationUriAsync