+ The enumeration is used with the enumeration to specify the alpha mode of a render target or bitmap. Different render targets and bitmaps support different alpha modes. For a list, see Supported Pixel Formats and Alpha Modes.
The Differences Between Straight and Premultiplied AlphaWhen describing an RGBA color using straight alpha, the alpha value of the color is stored in the alpha channel. For example, to describe a red color that is 60% opaque, you'd use the following values: (255, 0, 0, 255 * 0.6) = (255, 0, 0, 153). The 255 value indicates full red, and 153 (which is 60 percent of 255) indicates that the color should have an opacity of 60 percent.
When describing an RGBA color using premultiplied alpha, each color is multiplied by the alpha value: (255 * 0.6, 0 * 0.6, 0 * 0.6, 255 * 0.6) = (153, 0, 0, 153).
Regardless of the alpha mode of the render target, D2D1_COLOR_F values are always interpreted as straight alpha. For example, when specifying the color of an for use with a bitmap that uses the premultiplied alpha mode, you'd specify the color just as you would if the bitmap used straight alpha. When you paint with the brush, Direct2D translates the color to the destination format for you.
Alpha Mode for Render TargetsRegardless of the alpha mode setting, a render target's contents support transparency. For example, if you draw a partially transparent red rectangle with a render target with an alpha mode of , the rectangle will appear pink (if the background is white), as you might expect.
If you draw a partially transparent red rectangle when the alpha mode is , the rectangle will appear pink (assuming the background is white) and you can see through it to whatever is behind the render target. This is useful when using a to render to a transparent window or when using an compatible render target (a render targeted created by the CreateCompatibleRenderTarget method) to create a bitmap that supports transparency.
ClearType and Alpha ModesIf you specify an alpha mode other than for a render target, the text antialiasing mode automatically changes from CLEARTYPE to GRAYSCALE. (When you specify an alpha mode of , Direct2D sets the alpha for you depending on the type of render target. For a list of what the setting resolves to for each render target, see the Supported Pixel Formats and Alpha Modes overview.)
You can use the SetTextAntialiasMode method to change the text antialias mode back to CLEARTYPE, but rendering ClearType text to a transparent surface can create unpredictable results. If you want to render ClearType text to an transparent render target, we recommend that you use one of the following two techniques.
- Use the PushAxisAlignedClip method to clip the render target to the area where the text will be rendered, then call the Clear method and specify an opaque color, then render your text.
- Use DrawRectangle to draw an opaque rectangle behind the area where the text will be rendered.
+
+