←Select platform

DiceEffectCommand Class

Summary

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 Imaging Pro and above toolkits.

Syntax

C#
VB
WinRT C#
C++
public class DiceEffectCommand : RasterCommand 
function Leadtools.ImageProcessing.SpecialEffects.DiceEffectCommand() 

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-bit and 16-bit grayscale and 48-bit and 64-bit color images. Support for 12-bit and 16-bit grayscale and 48-bit 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.

Example

Run the DiceEffectCommand on an image.

C#
VB
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing.SpecialEffects; 
 
public void DiceEffectCommandExample() 
{ 
   // Load an image 
   RasterCodecs codecs = new RasterCodecs(); 
   codecs.ThrowExceptionsOnInvalidImages = true; 
 
   RasterImage image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, @"ImageProcessingDemo\Image2.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, Path.Combine(LEAD_VARS.ImagesDir, "Result.jpg"), RasterImageFormat.Jpeg, 24); 
 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images"; 
} 
Imports Leadtools 
Imports Leadtools.Codecs 
Imports Leadtools.ImageProcessing.SpecialEffects 
      Leadtools.Examples.Support.SetLicense() 
 
Public Sub DiceEffectCommandExample() 
   Dim codecs As New RasterCodecs() 
   codecs.ThrowExceptionsOnInvalidImages = True 
 
   Dim leadImage As RasterImage = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "ImageProcessingDemo\\Image2.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, Path.Combine(LEAD_VARS.ImagesDir, "Result.jpg"), RasterImageFormat.Jpeg, 24) 
 
End Sub 
 
Public NotInheritable Class LEAD_VARS 
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" 
End Class 

Requirements

Target Platforms

Help Version 19.0.2017.10.18
Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.ImageProcessing.SpecialEffects Assembly