Leadtools.ImageProcessing.SpecialEffects Send comments on this topic. | Back to Introduction - All Topics | Help Version 15.12.11
DiceEffectCommand Class
See Also  Members   Example 
Leadtools.ImageProcessing.SpecialEffects Namespace : DiceEffectCommand 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. This command is available in the Raster Pro and above toolkits.

Syntax

Visual Basic (Declaration) 
Public Class DiceEffectCommand 
   Inherits RasterCommand
   Implements IRasterCommand 
Visual Basic (Usage)Copy Code
Dim instance As DiceEffectCommand
C# 
public class DiceEffectCommand : RasterCommand, IRasterCommand  
Managed Extensions for C++ 
public __gc class DiceEffectCommand : public RasterCommand, IRasterCommand  
C++/CLI 
public ref class DiceEffectCommand : public RasterCommand, IRasterCommand  

Example

Visual BasicCopy Code
ImageProcessing.SpecialEffects.DiceEffectCommand
   Public Sub DiceEffectCommandExample()
      RasterCodecs.Startup()
      Dim codecs As New RasterCodecs()
      codecs.ThrowExceptionsOnInvalidImages = True

      Dim leadImage As RasterImage = codecs.Load("C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Master.jpg")

      ' Prepare the command
      Dim command As DiceEffectCommand = New DiceEffectCommand
      command.XBlock = 16
      command.YBlock = 16
      command.Randomize = 0
      command.Flags = DiceEffectCommandFlags.Count Or DiceEffectCommandFlags.Border
      command.BorderColor = New RasterColor(0, 0, 0)
      ' Apply Dice Effect for this image.
      command.Run(leadImage)
      codecs.Save(leadImage, "C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Result.jpg", RasterImageFormat.Jpeg, 24)

      RasterCodecs.Shutdown()
   End Sub
C#Copy Code
ImageProcessing.SpecialEffects.DiceEffectCommand 
      public void DiceEffectCommandExample() 
      { 
         // Load an image 
         RasterCodecs.Startup(); 
         RasterCodecs codecs = new RasterCodecs(); 
         codecs.ThrowExceptionsOnInvalidImages = true; 
 
         RasterImage image = codecs.Load(@"C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Master.jpg"); 
 
         // Prepare the command 
         DiceEffectCommand command  = new DiceEffectCommand(); 
         command.XBlock      = 16; 
         command.YBlock      = 16; 
         command.Randomize   = 0; 
         command.Flags       = DiceEffectCommandFlags.Count | 
                                 DiceEffectCommandFlags.Border; 
         command.BorderColor = new RasterColor(0, 0, 0); 
         // Apply Dice Effect for this image. 
         command.Run(image); 
         codecs.Save(image, @"C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Result.jpg", RasterImageFormat.Jpeg, 24); 
 
         RasterCodecs.Shutdown(); 
      }

Remarks

  • This command can process the whole image or a region of the image. If the image has a region, the effect is applied only to the region.
  • This command divides the image into a certain number of blocks according to the Flags property, or the flags parameter of the Constructor. If the DiceEffectCommandFlags.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, or can be designated in the Constructor.
  • If the DiceEffectCommandFlags.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, or can be designated in the Constructor.
  • The DiceEffectCommandFlags.Count flag or DiceEffectCommandFlags.Size flag (but not both) must be set.
  • If the DiceEffectCommandFlags.Border flag is also set, borders will be drawn around the dice blocks and it will be painted using the BorderColor property (or the borderColor parameter of the Constructor). If the DiceEffectCommandFlags.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 DiceEffectCommandFlags.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 DiceEffectCommandFlags.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 DiceEffectCommandFlags.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 DiceEffectCommandFlags.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 or the randomize parameter of the Constructor).
  • 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 or the flags parameter of the Constructor, the command leaves the image unchanged.
  • This command supports all bits/pixel supported by LEADTOOLS.
  • This command supports 12 and 16-bit grayscale and 48 and 64-bit color images. Support for 12 and 16-bit grayscale and 48 and 64-bit color images is available only in the Document/Medical toolkits.
  • This command does not support signed data images.
  • This command does not support 32-bit grayscale images.
For more information, refer to Applying Artistic Effects.

Inheritance Hierarchy

System.Object
   Leadtools.ImageProcessing.RasterCommand
      Leadtools.ImageProcessing.SpecialEffects.DiceEffectCommand

Requirements

Target Platforms: Microsoft .NET Framework 2.0, Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also