2016-12-18 8 views
1

最近隣のスケーリングを使用してUWPで画像をズームしようとしています。 WPFでは、私はRenderOptions.SetBitmapScalingMode(image, BitmapScalingMode.NearestNeighbor);を使用しました。 UWPでも同じ結果を得るにはどうすればよいですか? WPFでUWPの最近傍レンダリング

EXAMPLE

+0

私はこれが可能であるとは思いません。関連するhttps://stackoverflow.com/questions/40120417/bitmap-smoothing-in-uwp –

答えて

0

iがRenderOptions.SetBitmapScalingMode(画像、BitmapScalingMode.NearestNeighbor)を使用;. UWPでも同じ結果を得るにはどうすればよいですか?

uwpでは、画像のスケーリングにはBitmapTransformを使用できます。 WPFでBitmapScalingMode.NearestNeighborを使用したのと同じ効果を得るには、BitmapInterpolationModeの値をNearestNeighborとする必要があります。あなたが参照できる

コード例は次のとおりです。

private async Task<IStorageFile> CreateNewImage(StorageFile sourceFile, int requestedMinSide, StorageFile resizedImageFile) 
{ 
    var imageStream = await sourceFile.OpenReadAsync(); 
    var decoder = await BitmapDecoder.CreateAsync(imageStream); 
    var originalPixelWidth = decoder.PixelWidth; 
    var originalPixelHeight = decoder.PixelHeight; 
    using (imageStream) 
    { 
     using (var resizedStream = await resizedImageFile.OpenAsync(FileAccessMode.ReadWrite)) 
     { 
      var encoder = await BitmapEncoder.CreateForTranscodingAsync(resizedStream, decoder); 
      double widthRatio = (double)requestedMinSide/originalPixelWidth; 
      double heightRatio = (double)requestedMinSide/originalPixelHeight; 
      uint aspectHeight = (uint)requestedMinSide; 
      uint aspectWidth = (uint)requestedMinSide; 
      uint cropX = 0, cropY = 0; 
      var scaledSize = (uint)requestedMinSide; 
      aspectHeight = (uint)(widthRatio * originalPixelHeight); 
      cropY = (aspectHeight - aspectWidth)/2; 
      encoder.BitmapTransform.InterpolationMode = BitmapInterpolationMode.NearestNeighbor; 
      encoder.BitmapTransform.ScaledHeight = aspectHeight; 
      encoder.BitmapTransform.ScaledWidth = aspectWidth; 
      encoder.BitmapTransform.Bounds = new BitmapBounds() 
      { 
       Width = scaledSize, 
       Height = scaledSize, 
       X = cropX, 
       Y = cropY, 
      }; 
      await encoder.FlushAsync(); 
     } 
    } 
    return resizedImageFile; 
} 
+0

@Omerあなたは解決しましたか? –

関連する問題