2016-08-28 57 views
0

我需要一點指導。我試圖創建一個橢圓形狀的圖像。要查看使用CachedImagewpf圖像剪輯橢圓4:3

我當前的代碼的圖像:

<Grid Width="100" Height="100"> 
     <cachedImage:Image Width="100" Height="100" Stretch="UniformToFill" VerticalAlignment="Center" HorizontalAlignment="Center" 
          ImageUrl="https://i.scdn.co/image/efe952d45a24a33360e98b4b42d313576e29cece" > 
      <Image.Clip> 
       <EllipseGeometry Center="50,50" RadiusX="50" RadiusY="50" /> 
      </Image.Clip> 
     </cachedImage:Image> 
    </Grid> 

Poroblem發生,如果圖像是4:3格式

這是我

enter image description here

我需要這

enter image description here

非常感謝。

+0

從CachedImage主頁:「如果我們使用HTTP協議顯示圖像的原生WPF圖像控制(由源設置一個HTTP URL),圖像將被從服務器每次下載控制被加載。「這不是真的。 WPF在從URI加載圖像時緩存圖像。根本不需要使用這個控件。改爲使用標準的WPF圖像控件。 – Clemens

+0

您可能想要閱讀導致對GitHub進行控制的[原始StackOverflow問題](http://stackoverflow.com/q/1878060/1136211)的最高評價答案。今天已經過時了。 – Clemens

回答

2

設置Width和圖像控制的Height,並在同一時間將Stretch=UniformToFill圖像不可避免地作物部分,除非其縱橫比的WidthHeight比完全匹配。

但是,您可以設置Stretch=Uniform並將Image控件放在另一個更大的網格中,該網格在外部網格中水平居中。您必須將Clip應用於外部電網。

<Grid Width="100" Height="100"> 
    <Grid Width="200" HorizontalAlignment="Center"> 
     <Image Stretch="Uniform" 
       Source="C:\Users\Public\Pictures\Sample Pictures\Koala.jpg"/> 
    </Grid> 
    <Grid.Clip> 
     <EllipseGeometry Center="50,50" RadiusX="50" RadiusY="50" /> 
    </Grid.Clip> 
</Grid> 
+0

非常感謝。它有幫助 – Patrik