Close

Relief for ODA Team in Ukraine

Learn more
ODA Drawings SDK
Transparency Functionality as an Integer-value

Transparency is represented as a 32-bit packed integer value that stores the transparency method and transparency components. Assignment of components depends on the method. It can be an alpha-value or transparency of other object (layer, block). The transparency object is declared by the following line:


OdCmTransparency clarity;

To get the transparency as an integer value, use the serializeOut() method that returns the transparency as a value of the OdUInt32 type. Use the hexadecimal format to represent the returned value. For example:


odPrintConsoleString(L"\nEntity Color value = %x", clarity.serializeOut());

The obtained transparency value can be separated by the components using the bit operations. For example:


OdUInt32 value = clarity.serializeOut();

if(((value >> 24) & 0x0F) == 2)
  odPrintConsoleString(L"\nTransparency Method is by Alpha that = %d", (value & 0xFF));

To set the transparency using an integer value, use the serializeIn() method that requires an integer value to set the transparency. The serializeIn() method uses 24 to 27 bits to specify the transparency method and 0 to 7 bits to specify the alpha value. If these bits contain incorrect values that the serializeIn() method generates the eInvalidInput exception. Use the try-catch statement for this method. For example:


try {
  clarity.serializeIn(0x02000033);     // Set alpha = 51 (20%)
  clarity.serializeIn(0x01000000);     // Set transparency by block
}
catch(OdError e) {  
  odPrintConsoleString(L"\nError %d - %s", e.code(), e.description());
}

To compare transparencies, use the (==) operator that returns True when two transparency instances are equal or False otherwise, and the (!=) operator that returns True when two transparency instances are not equal or False otherwise. These operators take into account the transparency method and transparency components when they compare instances, which compare the transparencies as integer numbers. For example:


clarity.serializeIn(0x02000033);       // Alpha = 51 (20%)
OdCmTransparency clarityX; 

clarityX.setAlpha(51);
odPrintConsoleString(L"\n[%x] == [%x] => %s", clarity.serializeOut(), clarityX.serializeOut(), 
                      ((clarity == clarityX) ? L"true" : L"false"));       // [0x02000033] == [0x02000033] => true
clarityX.setAlpha(30);
odPrintConsoleString(L"\n[%x] == [%x] => %s", clarity.serializeOut(), clarityX.serializeOut(), 
                      ((clarity == clarityX) ? L"true" : L"false"));       // [0x02000033] == [0x0200001E] => false
clarityX.setMethod(OdCmTransparency::kByBlock);
odPrintConsoleString(L"\n[%x] != [%x] => %s", clarity.serializeOut(), clarityX.serializeOut(), 
                      ((clarity != clarityX) ? L"true" : L"false"));       // [0x02000033] == [0x01000000] => true

The assignment operator copies the specified transparency value from one instance to another instance, keeping the transparency method and transparency components. For example:


clarityX.serializeIn(0x0200001E);

clarity = clarityX;                                                        // Assignment operator

odPrintConsoleString(L"\nTransparency = [%x] (Alpha = %d)", clarity.serializeOut(), clarity.alpha());

// Result:  Transparency = [0x0200001E] (Alpha = 30)

See Also

Working with Colors and Transparencies

Methods of the Transparency Definition

Example of Working with Transparency

Copyright © 2002 – 2022. Open Design Alliance. All rights reserved.