简体   繁体   English

c#中的图像边框

[英]Border around image in c#

如何在c#中的图像周围有黑色边框。图像存在于包裹面板内

Just add a border to the Image: 只需为图像添加边框:

<toolkit:WrapPanel x:Name="wp">
    <Border BorderBrush="Black" BorderThickness="5" >
        <Image Source="myimage.png" />
    </Border>
</toolkit:WrapPanel>

Or add it to the WrapPanel in code: 或者在代码中将其添加到WrapPanel:

var b = new Border
            {
                BorderBrush = new SolidColorBrush(Colors.Black),
                BorderThickness = new Thickness(5)
            };

var bi = new BitmapImage
                {
                    UriSource = new Uri("/myimage.png", UriKind.Relative)
                };

b.Child = new Image {Source = bi};

wp.Children.Add(b);

Use a border element and configure it and set the background to a imagebrush with your image as source. 使用边框元素并对其进行配置,并将背景设置为以图像为源的图像画笔。

Here´s some XAML: 这是一些XAML:

    <Border BorderBrush="Black">
      <Border.Background>
        <ImageBrush ImageSource="<Your Image>"/>
      </Border.Background>
    </Border>

You can also define a CornerRadius on the Border to make rounded corners. 您还可以在边框上定义CornerRadius以制作圆角。 This will also apply to the image. 这也适用于图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM