2015-05-17 42 views
3

简单的应用程序,只显示图像列表。图像列表必须保持纵横比,但是全窗宽+有一点余量。困难的部分是使图像还有圆角​​。win10应用程序 - 保持宽高比的圆角图像

想法?

我所拥有的成功只有ImageBrush,但是使用它的任何控件都不会保持宽高比。例如,在这里你必须设置高度和宽度。

<Rectangle RadiusX="10" RadiusY="10" Stretch="Fill" Width="100" Height="100" > 
    <Rectangle.Fill> 
     <ImageBrush ImageSource="{Binding}"></ImageBrush> 
    </Rectangle.Fill> 
</Rectangle> 

完整的源代码在这里:http://1drv.ms/1HlZHVe

回答

0

我通过使用图像刷了我的图像(在我的UWP应用程序)很好的圆角,但是要小心,如果你这样做编程方式 - 我第一次做了我设法使用我的记忆力很差,而且消耗太多(糟糕的编码)。

我使用的ImageBrush很像你似乎是,但我没有得到任何畸变的纵横比;确保你正确设置了Stretch这样的属性 - 例如Stretch.UniformToFill

<Rectangle x:Name="rctCardFace" Margin="0" RadiusX="20" RadiusY="20" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"> 
    <Rectangle.Fill> 
     <ImageBrush Stretch="UniformToFill"/> 
    </Rectangle.Fill> 
</Rectangle> 

或者在C#

Uri path = new Uri(_ActiveStyle.BackgroundImagePath, UriKind.Absolute); 
BitmapImage bitmapImage = new BitmapImage(path); 

if (_AppReference.CardManager.TempImgBrush == null) 
{ 
    _AppReference.CardManager.TempImgBrush = new ImageBrush(); 
} 

_AppReference.CardManager.TempImgBrush.ImageSource = bitmapImage; 
_AppReference.CardManager.TempImgBrush.Stretch = _ActiveStyle.BackgroundImageStretch; 
_AppReference.CardManager.TempImgBrush.AlignmentX = _ActiveStyle.BackgroundImageAlignX; 
_AppReference.CardManager.TempImgBrush.AlignmentY = _ActiveStyle.BackgroundImageAlignY; 
cfPreview.ImgB = _AppReference.CardManager.TempImgBrush; 
1

嗨,你可以使用下面的代码来创建UWP圆角图片:

<Ellipse Width="250" Height="250"> 
    <Ellipse.Fill> 
     <ImageBrush ImageSource="ms-appx:///highfive.jpg" /> 
    </Ellipse.Fill> 
</Ellipse>