ID2D1Geometry::CombineWithGeometry 方法

將此幾何與指定的幾何結合,並將結果儲存在 ID2D1SimplifiedGeometrySink 中。

多載清單

方法 描述
CombineWithGeometry(ID2D1Geometry*,D2D1_COMBINE_MODE,D2D1_MATRIX_3X2_F&,ID2D1SimplifiedGeometrySink*) 將此幾何與指定的幾何結合,並將結果儲存在 ID2D1SimplifiedGeometrySink 中。
CombineWithGeometry(ID2D1Geometry*,D2D1_COMBINE_MODE,D2D1_MATRIX_3X2_F*,ID2D1SimplifiedGeometrySink*) 將此幾何與指定的幾何結合,並將結果儲存在 ID2D1SimplifiedGeometrySink 中。
CombineWithGeometry(ID2D1Geometry*,D2D1_COMBINE_MODE,D2D1_MATRIX_3X2_F&,FLOAT,ID2D1SimplifiedGeometrySink*) 將此幾何與指定的幾何結合,並將結果儲存在 ID2D1SimplifiedGeometrySink 中。
CombineWithGeometry(ID2D1Geometry*,D2D1_COMBINE_MODE,D2D1_MATRIX_3X2_F*,FLOAT,ID2D1SimplifiedGeometrySink*) 將此幾何與指定的幾何結合,並將結果儲存在 ID2D1SimplifiedGeometrySink 中。

範例

下列程式代碼會使用每個不同的合併模式來結合兩個 ID2D1EllipseGeometry 物件。

HRESULT DemoApp::CreateGeometryResources()
{
    HRESULT hr = S_OK;
    ID2D1GeometrySink *pGeometrySink = NULL;

    // Create the first ellipse geometry to merge.
    const D2D1_ELLIPSE circle1 = D2D1::Ellipse(
        D2D1::Point2F(75.0f, 75.0f),
        50.0f,
        50.0f
        );

    hr = m_pD2DFactory->CreateEllipseGeometry(
        circle1,
        &m_pCircleGeometry1
        );

    if (SUCCEEDED(hr))
    {
        // Create the second ellipse geometry to merge.
        const D2D1_ELLIPSE circle2 = D2D1::Ellipse(
            D2D1::Point2F(125.0f, 75.0f),
            50.0f,
            50.0f
            );

        hr = m_pD2DFactory->CreateEllipseGeometry(circle2, &m_pCircleGeometry2);
    }


    if (SUCCEEDED(hr))
    {
        //
        // Use D2D1_COMBINE_MODE_UNION to combine the geometries.
        //
        hr = m_pD2DFactory->CreatePathGeometry(&m_pPathGeometryUnion);

        if (SUCCEEDED(hr))
        {
            hr = m_pPathGeometryUnion->Open(&pGeometrySink);

            if (SUCCEEDED(hr))
            {
                hr = m_pCircleGeometry1->CombineWithGeometry(
                    m_pCircleGeometry2,
                    D2D1_COMBINE_MODE_UNION,
                    NULL,
                    NULL,
                    pGeometrySink
                    );
            }

            if (SUCCEEDED(hr))
            {
                hr = pGeometrySink->Close();
            }

            SafeRelease(&pGeometrySink);
        }
    }

    if (SUCCEEDED(hr))
    {
        //
        // Use D2D1_COMBINE_MODE_INTERSECT to combine the geometries.
        //
        hr = m_pD2DFactory->CreatePathGeometry(&m_pPathGeometryIntersect);

        if (SUCCEEDED(hr))
        {
            hr = m_pPathGeometryIntersect->Open(&pGeometrySink);

            if (SUCCEEDED(hr))
            {
                hr = m_pCircleGeometry1->CombineWithGeometry(
                    m_pCircleGeometry2,
                    D2D1_COMBINE_MODE_INTERSECT,
                    NULL,
                    NULL,
                    pGeometrySink
                    );
            }

            if (SUCCEEDED(hr))
            {
                hr = pGeometrySink->Close();
            }

            SafeRelease(&pGeometrySink);
        }
    }

    if (SUCCEEDED(hr))
    {
        //
        // Use D2D1_COMBINE_MODE_XOR to combine the geometries.
        //
        hr = m_pD2DFactory->CreatePathGeometry(&m_pPathGeometryXOR);

        if (SUCCEEDED(hr))
        {
            hr = m_pPathGeometryXOR->Open(&pGeometrySink);

            if (SUCCEEDED(hr))
            {
                hr = m_pCircleGeometry1->CombineWithGeometry(
                    m_pCircleGeometry2,
                    D2D1_COMBINE_MODE_XOR,
                    NULL,
                    NULL,
                    pGeometrySink
                    );
            }

            if (SUCCEEDED(hr))
            {
                hr = pGeometrySink->Close();
            }

            SafeRelease(&pGeometrySink);
        }
    }

    if (SUCCEEDED(hr))
    {
        //
        // Use D2D1_COMBINE_MODE_EXCLUDE to combine the geometries.
        //
        hr = m_pD2DFactory->CreatePathGeometry(&m_pPathGeometryExclude);

        if (SUCCEEDED(hr))
        {
            hr = m_pPathGeometryExclude->Open(&pGeometrySink);

            if (SUCCEEDED(hr))
            {
                hr = m_pCircleGeometry1->CombineWithGeometry(
                    m_pCircleGeometry2,
                    D2D1_COMBINE_MODE_EXCLUDE,
                    NULL,
                    NULL,
                    pGeometrySink
                    );
            }

            if (SUCCEEDED(hr))
            {
                hr = pGeometrySink->Close();
            }

            SafeRelease(&pGeometrySink);
        }
    }

    return hr;
}

此程式代碼會產生下圖所示的輸出。

illustration of two ellipses combined by using four geometry combine modes (union, intersect, xor, and exclude)

需求

需求
程式庫
D2d1.lib
DLL
D2d1.dll

另請參閱

ID2D1Geometry