2016-10-17 8 views
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; 
    } 

WriteableBitmapは、コンストラクタで入力パラメータとしてピクセルの高さと幅を必要とするので、私はBitmapImageのを使用します。 はここに私のコードです。 MS-APPX:///Images/contact.png

+0

なぜを使用する必要はありませんウリは、例えばありますcontactSmall.png、contactMedium.png、contactLarge.pngのように、サイズの異なる3つの画像ファイルがありませんか?それ以外に、あなたのメソッドから返されたWriteableBitmapがBitmapImageが生成するちらつきを避ける理由は不明です。 – Clemens

+0

私はcontact.scale-100.png、contact.scale-200.png、contact.scale-400.pngを持っています。私がImagesourceにuriを直接バインドすると、システムはどのスケーリングファクタを選択するかを知っていますが、イメージを変更すると常にちらつきます。 BitmapImage/WriteableBitmapはちらつきを解決しましたが、常に最大の倍率で画像を取得します。 – JuP

+0

それは動作します。しかし私は手動でこれをやりたいとは思わない。システムは、現在の解像度などに基づいてどのイメージを使用するかを決定する必要があります。 'ImageSource = "/ Images/contant.png"'は、適切なイメージを使用します。 – JuP

答えて

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

関連する問題