次の方法で共有


方法 : イメージの一部に効果を適用する

更新 : 2007 年 11 月

この例では、BitmapEffectInput プロパティを使用して、Image の一部に BitmapEffect を適用する方法を示します。

使用例

次の例では、ビジュアル コンテンツの一部分に効果を適用する 2 つの方法を示します。

<Page xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml">
  <Page.Resources>
    <BitmapImage x:Key="sourceImage" UriSource="/images/WaterLilies.jpg"/>
  </Page.Resources>

  <StackPanel>
    <DockPanel>
      <StackPanel DockPanel.Dock="Left">
        <TextBlock>AreaToApplyEffect=".25,.25,.50,.50"</TextBlock>
        <TextBlock>AreaToApplyEffectUnits="RelativeToBoundingBox"</TextBlock>
      </StackPanel>
      <Image Width="360" Source="{StaticResource sourceImage}" Margin="10" DockPanel.Dock="Left">
        <Image.BitmapEffect>

          <!-- <BitmapEffectGroup> would go here if you wanted to apply more 
             then one effect to the TextBox. However, in this example only  
             one effect is being applied so BitmapEffectGroup does not need  
             to be included. -->

          <!-- Effect to Apply to the Image -->
          <EmbossBitmapEffect Relief="0.8" LightAngle="320" />
        </Image.BitmapEffect>
        <Image.BitmapEffectInput>

          <!-- BitmapEffectInput is used to apply the bitmap effect to a specified
                 region of the visual. When this property is not used, the effect
                 is applied to the entire visual.

               AreaToApplyEffect is a rectangular area in which to apply the effect.
               - When AreaToApplyEffectUnits is "Absolute", the rectangle is read as
                 pixel coordinates within the visual.
               - When AreaToApplyEffectUnits is "RelativeToBoundingBox",
                 the rectangle values are relative to the entire bounding box.
                 Values range between 0 and 1, where (0,0) is the top-left corner
                 and (1,1) is the bottom-right corner. -->

          <BitmapEffectInput AreaToApplyEffect=".25,.25,.50,.50" AreaToApplyEffectUnits="RelativeToBoundingBox"/>
        </Image.BitmapEffectInput>
      </Image>
    </DockPanel>
    <DockPanel>
      <StackPanel DockPanel.Dock="Left">
        <TextBlock>AreaToApplyEffect="90,66,180,135"</TextBlock>
        <TextBlock>AreaToApplyEffectUnits="Absolute"</TextBlock>
      </StackPanel>
      <Image Width="360" Source="{StaticResource sourceImage}" Margin="10" DockPanel.Dock="Left">
        <Image.BitmapEffect>

          <!-- <BitmapEffectGroup> would go here if you wanted to apply more 
             then one effect to the TextBox. However, in this example only  
             one effect is being applied so BitmapEffectGroup does not need  
             to be included. -->

          <!-- Effect to Apply to the Image -->
          <EmbossBitmapEffect Relief="0.8" LightAngle="320" />
        </Image.BitmapEffect>
        <Image.BitmapEffectInput>

          <!-- BitmapEffectInput is used to apply the bitmap effect to a specified
                 region of the visual. When this property is not used, the effect
                 is applied to the entire visual.

             AreaToApplyEffect is a rectangular area in which to apply the effect.
               - When AreaToApplyEffectUnits is "Absolute", the rectangle is read as
                 pixel coordinates within the visual.
               - When AreaToApplyEffectUnits is "RelativeToBoundingBox",
                 the rectangle values are relative to the entire bounding box.
                 Values range between 0 and 1, where (0,0) is the top-left corner
                 and (1,1) is the bottom-left corner. -->

          <BitmapEffectInput AreaToApplyEffect="90,66,180,135" AreaToApplyEffectUnits="Absolute"/>
        </Image.BitmapEffectInput>
      </Image>
    </DockPanel>
  </StackPanel>

</Page>

次の図は、イメージの中央だけに適用されたエンボス効果を示しています。

イメージの一部に対するエンボス効果。

参照

参照

EmbossBitmapEffect