0
由於圖像閃爍我使用了WriteableBitmap。我有3個比例因子的圖像。但是GetFileFromApplicationUriAsync總是讀取具有最高縮放因子的圖像,並且移動設備上的圖像太大。 這裏是我的代碼:WriteableBitmap和縮放因子
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
爲什麼沒有3個不同大小的圖像文件,如contactSmall.png,contactMedium.png和contactLarge.png?除此之外,目前還不清楚爲什麼從您的方法返回的WriteableBitmap會避免BitmapImage產生閃爍。 – Clemens
我有contact.scale-100.png,contact.scale-200.png,contact.scale-400.png。如果我直接將uri綁定到Imagesource,那麼系統知道,選擇哪個縮放因子,但是當我更改圖像時,它會始終閃爍。 BitmapImage/WriteableBitmap解決了閃爍問題,但它總是以最高的比例因子拍攝圖像。 – JuP
它會工作。但我不想手動執行此操作。系統應該根據當前的場景分辨率等來決定使用哪個圖像。如果我這樣做:'ImageSource ='/ Images/contant.png'',它使用適合的圖像。 – JuP