Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 可以加载矩形或椭圆的图像吗?_C#_Wpf - Fatal编程技术网

C# 可以加载矩形或椭圆的图像吗?

C# 可以加载矩形或椭圆的图像吗?,c#,wpf,C#,Wpf,我正在做的WPF的工作,使二维足球比赛。如何添加椭圆的图像?我学会了如何移动矩形和椭圆,但不能用足球图像来实现 <Window x:Class="PaddingBall.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Padding Ball v1.0" Height

我正在做的WPF的工作,使二维足球比赛。如何添加椭圆的图像?我学会了如何移动矩形和椭圆,但不能用足球图像来实现

<Window x:Class="PaddingBall.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Padding Ball v1.0" Height="500" Width="700" Background="Gray" Name="playground" ResizeMode="NoResize" WindowStartupLocation="CenterScreen" SizeToContent="Manual">
<Canvas Width="700" Height="500">
    <Menu VerticalAlignment="Top" HorizontalAlignment="Left"            
         Height="20" Width="700" Background="AliceBlue" Foreground="Blue">
        <MenuItem Header="File">
            <MenuItem Header="Start Game" Background="AliceBlue" Click="StartGame"></MenuItem>
            <MenuItem Header="Exit" Background="AliceBlue" Click="ExitGame"></MenuItem>
        </MenuItem>
        <MenuItem Header="About" Click="ShowAboutBox"></MenuItem>
    </Menu>

    <Grid Height="462" Width="700" Canvas.Left="-106" Canvas.Top="-22">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="700*" />
            <ColumnDefinition Width="0*" />
            <ColumnDefinition Width="0*" />
        </Grid.ColumnDefinitions>
        <Ellipse Margin="114,132,0,0" Name="ball" Stroke="Black" Fill="Blue" Height="38" VerticalAlignment="Top" Stretch="UniformToFill" HorizontalAlignment="Left" Width="38">
            <Ellipse.BitmapEffect>
                <BevelBitmapEffect BevelWidth="11" />
            </Ellipse.BitmapEffect>
                <Ellipse.BitmapEffectInput>
                    <BitmapEffectInput />
                </Ellipse.BitmapEffectInput>
        </Ellipse>
        <Rectangle Height="13" Margin="200,390,0,0" Name="pad" Stroke="Black" VerticalAlignment="Bottom" Fill="Black" HorizontalAlignment="Left" Width="100" />
    </Grid>
</Canvas>


用图像笔刷填充椭圆:

<Ellipse ...>
    <Ellipse.Fill>
        <ImageBrush ImageSource="ball.jpg"/>
    </Ellipse.Fill>
</Ellipse>

正如克莱门斯所回答的,这两种情况都是一样的

对于矩形,它是:

<Rectangle>
    <Rectangle.Fill>
        <ImageBrush ImageSource="Pic.jpg"/>
    </Rectangle.Fill>
</Rectangle>

对于椭圆:

<Ellipse>
    <Ellipse.Fill>
        <ImageBrush ImageSource="Pic.jpg"/>
    </Ellipse.Fill>
</Ellipse>