圆角的图像

时间:2015-12-17 01:01:46

标签: c# windows-phone-8.1

我想问你应该怎么做才能绕过'Image'控件的一角。我试过了,但它不起作用。这是代码:

EllipseGeometry elipse = new EllipseGeometry();
elipse.Center = new Point(16, 16);
elipse.RadiusX = 32;
elipse.RadiusY = 32;
//
//
//
firstSpellImage.Clip = elipse;

其中firstSpellImage是Image类的实例。此图片大小为32x32。

1 个答案:

答案 0 :(得分:0)

您需要在边框背景中添加图像画笔,并围绕边框控件的任何一角。这是如何。

  <Border HorizontalAlignment="Left" Margin="0" VerticalAlignment="Bottom" Width="100"  Height="100" BorderBrush="White" BorderThickness="1"
                               CacheMode="BitmapCache" CornerRadius="40,0,30,0"><!-- left-top and bottom-right round corners. -->
        <Border.Background>
            <ImageBrush ImageSource="https://bushrasbrilliantblog.files.wordpress.com/2014/10/placid_nature.jpg"  Stretch="Fill"></ImageBrush>
        </Border.Background>
    </Border>

希望这有帮助

修改 寡妇手机中的圆角图像在C#中获胜 -

在这里你需要使用imagebrush而不是image

Border border = new Border();
border.Width = 200d;
border.Height = 200d;
border.CornerRadius = new CornerRadius(0, 100, 0, 100);
border.BorderBrush = new SolidColorBrush(Windows.UI.Colors.Green);
border.BorderThickness = new Thickness(2.5d);

ImageBrush img = new ImageBrush();
img.ImageSource = new Windows.UI.Xaml.Media.Imaging.BitmapImage(new Uri("https://bushrasbrilliantblog.files.wordpress.com/2014/10/placid_nature.jpg", UriKind.RelativeOrAbsolute));
img.Stretch = Stretch.Fill;
border.Background = img;

LayoutRoot.Children.Add(border);