Leadtools.Windows.Media.Effects Send comments on this topic. | Back to Introduction - All Topics | Help Version 15.02.15
DiceEffectCommandBitmapEffect Class
See Also  Members   Example 
Leadtools.Windows.Media.Effects.SpecialEffects Namespace : DiceEffectCommandBitmapEffect Class





Splits the image into square or rectangular blocks. If the blocks are square, the command rotates each block by 0, 90, 180, or 270 degrees. If the blocks are rectangular, the command flips the blocks around the X-axis or Y-axis.

Syntax

Visual Basic (Declaration) 
Public Class DiceEffectCommandBitmapEffect 
   Inherits RasterCommandBitmapEffect
Visual Basic (Usage)Copy Code
Dim instance As DiceEffectCommandBitmapEffect
C# 
public class DiceEffectCommandBitmapEffect : RasterCommandBitmapEffect 
Managed Extensions for C++ 
public __gc class DiceEffectCommandBitmapEffect : public RasterCommandBitmapEffect 
C++/CLI 
public ref class DiceEffectCommandBitmapEffect : public RasterCommandBitmapEffect 
XAML Property Element Usage 

DiceEffectCommandBitmapEffect ...

Example

Visual BasicCopy Code
Public Sub DiceEffectCommandBitmapEffectExample(ByVal element As FrameworkElement)

   ' Initialize Effect
   Dim effect As DiceEffectCommandBitmapEffect = New DiceEffectCommandBitmapEffect()
   effect.XBlock = 10
   effect.YBlock = 10
   effect.Randomize = 0
   element.BitmapEffect = effect

   ' Initialize Animations
   Dim animation1 As Int32Animation = New Int32Animation()
   animation1.From = 5
   animation1.To = 15
   animation1.By = 1
   animation1.Duration = New Duration(TimeSpan.FromSeconds(2.0))
   animation1.AutoReverse = True
   animation1.RepeatBehavior = RepeatBehavior.Forever
   Dim animation2 As Int32Animation = New Int32Animation()
   animation2.From = 5
   animation2.To = 20
   animation2.By = 1
   animation2.Duration = New Duration(TimeSpan.FromSeconds(3.0))
   animation2.AutoReverse = True
   animation2.RepeatBehavior = RepeatBehavior.Forever

   ' Initialize and run Storyboard
   Dim storyboard As Storyboard = New Storyboard()
   storyboard.SetTargetName(animation1, "AnimatedBitmapEffect")
   storyboard.SetTargetProperty(animation1, New PropertyPath(DiceEffectCommandBitmapEffect.XBlockProperty))
   element.RegisterName("AnimatedBitmapEffect", effect)
   storyboard.Children.Add(animation1)
   storyboard.SetTargetProperty(animation2, New PropertyPath(DiceEffectCommandBitmapEffect.YBlockProperty))
   element.RegisterName("AnimatedBitmapEffect", effect)
   storyboard.Children.Add(animation2)

   storyboard.Begin(element)
End Sub
C#Copy Code
public void DiceEffectCommandBitmapEffectExample(FrameworkElement element) 

 
   // Initialize Effect 
   DiceEffectCommandBitmapEffect effect = new DiceEffectCommandBitmapEffect(); 
   effect.XBlock = 10; 
   effect.YBlock = 10; 
   effect.Randomize = 0; 
   effect.Flags = DiceEffectCommandBitmapEffectsFlags.Count | 
                  DiceEffectCommandBitmapEffectsFlags.Border; 
   effect.BorderColor = System.Windows.Media.Color.FromRgb(0, 0, 0); 
 
   element.BitmapEffect = effect; 
 
   // Initialize Animations 
   Int32Animation animation1 = new Int32Animation(); 
   animation1.From = 5; 
   animation1.To = 15; 
   animation1.By = 1; 
   animation1.Duration = new Duration(TimeSpan.FromSeconds(2.0)); 
   animation1.AutoReverse = true; 
   animation1.RepeatBehavior = RepeatBehavior.Forever; 
   Int32Animation animation2 = new Int32Animation(); 
   animation2.From = 5; 
   animation2.To = 20; 
   animation2.By = 1; 
   animation2.Duration = new Duration(TimeSpan.FromSeconds(3.0)); 
   animation2.AutoReverse = true; 
   animation2.RepeatBehavior = RepeatBehavior.Forever; 
 
   // Initialize and run Storyboard 
   Storyboard storyboard = new Storyboard(); 
   Storyboard.SetTargetName(animation1, "AnimatedBitmapEffect"); 
   Storyboard.SetTargetProperty(animation1, new PropertyPath(DiceEffectCommandBitmapEffect.XBlockProperty)); 
   element.RegisterName("AnimatedBitmapEffect", effect); 
   storyboard.Children.Add(animation1); 
   Storyboard.SetTargetProperty(animation2, new PropertyPath(DiceEffectCommandBitmapEffect.YBlockProperty)); 
   element.RegisterName("AnimatedBitmapEffect", effect); 
   storyboard.Children.Add(animation2); 
 
   storyboard.Begin(element); 
}
XAMLCopy Code
<Page Title="CSAnimateEffect" Height="391" Width="300" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:lteffects="clr-namespace:Leadtools.Windows.Media.Effects.SpecialEffects;assembly=Leadtools.Windows.Media.Effects"> 
  <Grid> 
    <Image Margin="10,10,10,10" HorizontalAlignment="Center" VerticalAlignment="Center" Source="C:\Program Files\LEAD Technologies, Inc\LEADTOOLS 15\Images\slave.jpg"> 
      <Image.BitmapEffect> 
        <lteffects:DiceEffectCommandBitmapEffect x:Name="MyBitmapEffect" XBlock="15" YBlock="15" Randomize="0" /> 
      </Image.BitmapEffect> 
      <Image.Triggers> 
        <EventTrigger RoutedEvent="Image.Loaded"> 
          <BeginStoryboard> 
            <Storyboard> 
              <Int32Animation Storyboard.TargetName="MyBitmapEffect" Storyboard.TargetProperty="XBlock" From="5" To="15" Duration="0:0:2" RepeatBehavior="Forever" AutoReverse="True" /> 
              <Int32Animation Storyboard.TargetName="MyBitmapEffect" Storyboard.TargetProperty="YBlock" From="5" To="20" Duration="0:0:3" RepeatBehavior="Forever" AutoReverse="True" /> 
            </Storyboard> 
          </BeginStoryboard> 
        </EventTrigger> 
      </Image.Triggers> 
    </Image> 
  </Grid> 
</Page>

Remarks

  • This command divides the image into a certain number of blocks according to the Flags property. If the DiceEffectCommandBitmapEffectsFlags.Size flag is set then the image will be divided into blocks according to the width and height for each block. The width and height are set in the XBlock and YBlock properties.
  • If the DiceEffectCommandBitmapEffectsFlags.Count flag is set then the image is divided into blocks according to the number of blocks per row and number of blocks per column. These values are also set in the XBlock and YBlock properties.
  • The DiceEffectCommandBitmapEffectsFlags.Count flag or DiceEffectCommandBitmapEffectsFlags.Size flag (but not both) must be set.
  • If the DiceEffectCommandBitmapEffectsFlags.Border flag is also set, borders will be drawn around the dice blocks and it will be painted using the BorderColor property. If the DiceEffectCommandBitmapEffectsFlags.ResizeImage flag is set then the image will be resized so that all blocks have the same size and so there is no remainder in the image, ensuring that all blocks in the image will be manipulated in the same way. If the DiceEffectCommandBitmapEffectsFlags.ResizeImage flag is not set then the edge blocks (which may be a different size than the inner blocks) will be treated differently than the inner blocks.
  • The Dice effect command works in the following manner:
  • It divides the image into a certain number of blocks.
  • If the DiceEffectCommandBitmapEffectsFlags.ResizeImage flag is set, the image is resized to the closest size to have the edge blocks have the same size as the inner blocks.
  • If the DiceEffectCommandBitmapEffectsFlags.ResizeImage flag is not set, then the inner blocks might have a different size and shape than the edge blocks. Each block is transformed according to its shape.
  • For each block, a rotation angle is picked at random out of the following values: 0, 90, 180, and 270. The rotation angle is applied depending on the block shape (square or rectangular):
  • If the block is square, it is rotated by the rotation angle.
  • If the block is rectangular, it is transformed as follows:
  • If the rotation angle is 0, the block remains unchanged.
  • If the rotation angle is 90, the block is flipped around the x-axis.
  • If the angle is 180, the block is rotated by 180.
  • If the angle is 270, the block is flipped around the y-axis.
  • If the DiceEffectCommandBitmapEffectsFlags.Border flag is set, the command draws borders around the blocks.
  • The starting point (or "randomize value") for the random number generator is set in the Randomize property.
  • If the randomize value is zero then the command itself selects a random value between 1 and 500 for the randomize value.
  • If the randomize value is > 0, it is used as the starting point.
  • Here are some tips related to the randomize point:
  • The sequence of generated random numbers is the same if you use the same randomize value > 0. In other words, if you call the command twice with the same randomize value, each block will be transformed the same way.
  • Calling the command 4 times with the same image and the same randomize value > 0 will leave the image blocks unchanged. So, if you call the command once, the blocks will be transformed. Call the command 3 more times and each block goes to its original transformation. Of course, if you elected to draw borders, there will be a grid drawn on the image.
  • If you pass 0 for the Flags property, the command leaves the image unchanged.
  • This command supports all bits/pixel supported by LEADTOOLS for WPF.
  • This command does not support signed data images.

Inheritance Hierarchy

System.Object
   System.Windows.Threading.DispatcherObject
      System.Windows.DependencyObject
         System.Windows.Freezable
            System.Windows.Media.Animation.Animatable
               System.Windows.Media.Effects.BitmapEffect
                  Leadtools.Windows.Media.Effects.RasterCommandBitmapEffect
                     Leadtools.Windows.Media.Effects.SpecialEffects.DiceEffectCommandBitmapEffect

Requirements

Target Platforms: Microsoft .NET Framework 3.0, Windows XP, Windows Vista, and Windows Server 2003

See Also