Drawings SDK Developer Guide > Working with .dwg Files > Working with Colors > Methods of the Transparency Definition
Methods of the Transparency Definition

The transparency method defines how the transparency is defined and what components are used. A transparency can be defined through an alpha-value (byAlpha), transparency of a layer (byLayer), or transparency of a block (byBlock). The alpha-value defines the transparency as an integer value in the fixed range in which a lower bound defines the clarity and an upper bound defines the opacity. When the transparency is defined through another object (layer or block), it uses the settings of the layer or block to which the object belongs. The 24 to 31 bits store the transparency method, and other bits store the transparency components.

The transparency defined by the byLayer or byBlock method does not have components and is identified only by the method number. The transparency defined by the byAlpha method has a component storing an alpha-value. The transparency object is declared by the following line:


OdCmTransparency clarity;

To get the transparency method, use the method() method that does not have arguments and returns the transparency method as an integer constant defined by the transparencyMethod enumeration. The transparency method occupies one half-byte in which the most significant half-byte always stores a zero and least significant half-byte stores the method number. Half-bytes together form the following values:  0x00 – kByLayer, 0x01 – kByBlock, 0x02 – kByAlpha. For example:


odPrintConsoleString(L"\nTransparency method = %x - is ", clarity.method());

switch(clarity.method())
{
  case OdCmTransparency::kByLayer:
       odPrintConsoleString(L"by Layer\n");
       break;
  case OdCmTransparency::kByBlock:
       odPrintConsoleString(L"by Block\n");
       break;
  case OdCmTransparency::kByAlpha:
       odPrintConsoleString(L"by Alpha\n");
       break;
}

To specify the transparency method, use the setMethod() method that requires the transparency method as a value of the transparencyMethod enumeration and does not return a value. For example:


clarity.setMethod(OdCmTransparency::kByAlpha)

Another example:


int method;

odPrintConsoleString(L"\nMethod: 0-ByLayer, 1-ByBlock, 2-ByAlpha");
odPrintConsoleString(L"\nSpecify the method:>");
scanf("%d", &method);

if(method == 0 || method == 1 || method == 2)
{
  clarity.setMethod((OdCmTransparency::transparencyMethod)method);
}

To check whether the transparency method is by layer, use the isByLayer() method that returns True when the transparency method is set to kByLayer or False otherwise. For example:


odPrintConsoleString(L"\nTransparency method %s byLayer", ((clarity.isByLayer()) ? L"is" : L"is not"));

To check whether the transparency method is by block, use the isByBlock() method that returns True when the transparency method is set to kByBlock or False otherwise. For example:


odPrintConsoleString(L"\nTransparency method %s byBlock", ((clarity.isByBlock()) ? L"is" : L"is not"));

To check whether the transparency method is by alpha, use the isByAlpha() method that returns True when the transparency method is set to kByAlpha or False otherwise. For example:


odPrintConsoleString(L"\nTransparency method %s byAlpha", ((clarity.isByAlpha()) ? L"is" : L"is not"));

Note: Calling the setMethod() method clears the transparency components.

See Also

Working with Colors and Transparencies

Transparency Functionality as an Alpha-value

Transparency Functionality as an Integer-value

Example of Working with Transparency

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