LBitmap::DiceEffect

Summary

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

Syntax

#include "ltwrappr.h"

virtual L_INT LBitmap::DiceEffect (uXBlock, uYBlock, uRandomize, uFlags, crColor)

Parameters

L_UINT uXBlock

If the DICE_SIZE flag is set, this parameter represents the width of the each block, in pixels. If the DICE_COUNT flag is set, this parameter represents the number of blocks per row.

L_UINT uYBlock

If the user set the DICE_SIZE flag, this parameter represents the height of the each block, in pixels. If the user set the DICE_COUNT flag instead of DICE_SIZE flag, this parameter will represent the number of blocks per column.

L_UINT uRandomize

The starting point for the randomization process. Valid values range from 0 through 500. Use 0 to have the function select the value.

L_UINT uFlags

Flags that specify how to apply the effect. Possible values are:

Value Meaning
DICE_BORDER [0x0001] Draw borders around the dice blocks. The border color is given by crColor. Each block will draw the border on the inside of the edges. The border is 1 pixel wide. In places with adjacent blocks, the border will be 2 pixels wide because each block has a 1-pixel border. If the BITMAP_RESIZE flag is not set and the edge blocks have a different size than the inner blocks, the border will not be drawn for the right and the bottom edges.
DICE_SIZE [0x0010] uXBlock and uYBlock contain the width and height of each block, in pixels.
DICE_COUNT [0x0020] uXBlock and uYBlock contain the number of blocks per row and per column.
BITMAP_RESIZE [0x0100] if this flag is set then the image will be resized to be sure that all blocks have equal size. If this flag is not set then the edge blocks might have a different size than the inner blocks. If the edge blocks have a different size, they will be manipulated differently. For more information, refer to the Comments section.

COLORREF crColor

Value that represents the color of the border that will be drawn around the dice blocks. This parameter will be used only if the DICE_BORDER flag is set.

Returns

Value Meaning
SUCCESS The function was successful.
< 1 An error occurred. Refer to Return Codes.

Comments

This function can process the whole image or a region of the image. If a bitmap has a region, the effect is applied only to the region.

This function divides the image into a certain number of blocks according to the uFlags parameter. If this flag is set to DICE_SIZE then the image will be divided into blocks according to the width and height for each block, which you set with the uXBlock and uYBlock parameters.

If the uFlags flag is set to DICE_COUNT then the image is divided into blocks according to the number of blocks per row and number of blocks per column you set with the uXBlock and uYBlock parameters.

The uFlags variable must contain DICE_COUNT or DICE_SIZE (but not both).

The uFlags variable can be or-ed with the DICE_BORDER and BITMAP_RESIZE flags. If the DICE_BORDER flag is set, borders will be drawn around the dice blocks and it will be painted by the crColor parameter. If the BITMAP_RESIZE 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 BITMAP_RESIZE 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 function works in the following manner:

It divides the image into a certain number of blocks.

If the BITMAP_RESIZE flag is set, the bitmap is resized to the closest size to have the edge blocks have the same size as the inner blocks.

If the BITMAP_RESIZE 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 DICE_BORDER flag is set, the function draws borders around the blocks.

The starting point (that is, the "randomize value") for the random number generator is selected through the uRandomize parameter.

If uRandomize is set to zero then the function itself selects a random value between 1 and 500 for the randomize value.

If uRandomize is > 0, it is used for the randomize value.

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 function twice with the same randomize value, each block will be transformed the same way.

Calling the function 4 times with the same bitmap and the same randomize value > 0 will leave the bitmap blocks unchanged. So, if you call the function once, the blocks will be transformed. Call the function 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 uFlags, the function leaves the image unchanged.

This function supports all bits/pixel supported by LEADTOOLS.

Support for 12 and 16-bit grayscale and 48 and 64-bit color images is available only in the Document/Medical toolkits.

To update a status bar or detect a user interrupt during execution of this function, refer to LBase::EnableStatusCallback.

This function does not support signed data images. It returns the error code ERROR_SIGNED_DATA_NOT_SUPPORTED if a signed data image is passed to this function.

This function does not support 32-bit grayscale images. It returns the error code ERROR_GRAY32_UNSUPPORTED if a 32-bit grayscale image is passed to this function.

Dice Effect Function - Before

Dice Effect Function - Before

Dice Effect Function - After

Dice Effect Function - After

View additional platform support for this Dice Effect function.

Required DLLs and Libraries

Platforms

Win32, x64.

See Also

Functions

Topics

Example

L_INT LBitmap__DiceEffectExample(LBitmap *pLeadBitmap)  
{ 
    
   /* This example applies a Dice Effect over the loaded image. */ 
   /* Apply Dice Effect for this bitmap */ 
   return pLeadBitmap->DiceEffect (16, 16,0, BITMAP_RESIZE | DICE_SIZE | DICE_BORDER, RGB(0,0,0));  
} 
Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Raster Imaging C++ Class Library Help
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.