2013-11-27 78 views
-1

我正在做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> 

回答

0

爲克萊門斯已經回答了這是兩者相同..

爲矩形,它是:

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

對於Ellipse:

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

與圖像刷填充的橢圓:

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