是否可以加载矩形或椭圆形图像?

时间:2013-11-27 19:08:55

标签: c# wpf

我正在WPF上做一个2D足球比赛。如何添加椭圆图像?我学会了如何移动矩形和椭圆,但不能用足球图像来实现。

<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>

2 个答案:

答案 0 :(得分:2)

使用ImageBrush填充Ellipse:

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

答案 1 :(得分:0)

对于两个人来说,克莱门斯已经回答了同样的事情。

对于Rectangle,它是:

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

对于Ellipse:

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