利用图层Layer绘制
资源网址:https://docs.microsoft.com/zh-cn/windows/win32/direct2d/direct2d-layers-overview
资源网址:https://docs.microsoft.com/zh-cn/windows/win32/direct2d/direct2d-layers-overview
1.创建图层属性
结构体原型如下
D2D1_LAYER_PARAMETERS layerParam = D2D1::LayerParameters( D2D1::InfiniteRect(), NULL, D2D1_ANTIALIAS_MODE_PER_PRIMITIVE, D2D1::IdentityMatrix(), 1.0, NULL, D2D1_LAYER_OPTIONS_NONE );//以上参数也是LayerParameters()的默认参数
struct D2D1_LAYER_PARAMETERS { D2D1_RECT_F contentBounds; //裁切矩形 ID2D1Geometry *geometricMask; //利用几何对象裁切 //tip:前两个属性事实上是二选一
D2D1_ANTIALIAS_MODE maskAntialiasMode; //反锯齿开关 D2D1_MATRIX_3X2_F maskTransform; //裁切变换矩阵 FlOAT opacity; //图层透明度 ID2D1Brush *opacityBrush; //透明度渐变刷(只有透明度起作用) D2D1_LAYER_OPTIONS layerOptions; }
2.利用图层绘制
2.1.创建图层
2.1.创建图层
ID2D1Layer *pLayer = NULL;
pRenderTarget->CreateLayer(NULL, &pLayer);
2.2.设定图层起始位置
pRenderTarget->SetTransform(D2D1::Matrix3x2F::Translation(300,250));
2.3.绘制图层
pRenderTarget->PushLayer(layerParam, pLayer); ......; //任意绘制代码,表示在图层上绘制图形 pRenderTarget->PopLayer();
2.4.释放图层
pLayer->Release();