Direct2D (18) : 图层之 TD2D1LayerParameters.contentBounds (图层的有效范围)



{相关方法}

TDirect2DCanvas.RenderTarget.CreateLayer(); //建立层

TDirect2DCanvas.RenderTarget.PushLayer();   //开始层;层的功能及效果取决于它的 TD2D1LayerParameters 结构参数

TDirect2DCanvas.RenderTarget.PopLayer();    //结束层



{相关结构}

TD2D1LayerParameters = record

  contentBounds: TD2D1RectF;             //层的有效范围

  geometricMask: ID2D1Geometry;          //用于剪裁的几何图形

  maskAntialiasMode: TD2D1AntiAliasMode; //抗锯齿模式

  maskTransform: TD2D1Matrix3x2F;        //2D 变换

  opacity: Single;                       //层的透明度

  opacityBrush: ID2D1Brush;              //蒙版画刷

  layerOptions: TD2D1LayerOptions;       //文本抗锯齿模式

end;



测试图层范围(用不同的透明度绘制了两次图片,第二次通过层指定了有效范围):


uses Direct2D, D2D1;



procedure TForm1.FormPaint(Sender: TObject);

var

  cvs: TDirect2DCanvas;

  iLayer: ID2D1Layer;

  rLayerParameters: TD2D1LayerParameters;

  wic: TWICImage;

  R: TRect;

begin

  wic := TWICImage.Create;

  wic.LoadFromFile('C:\Temp\Test.png');

  R := Rect(0, 0, wic.Width, wic.Height);



  cvs := TDirect2DCanvas.Create(Canvas, ClientRect);

  cvs.RenderTarget.SetTransform(TD2DMatrix3x2F.Translation((ClientWidth-wic.width)/2, (ClientHeight-wic.height)/2));

  cvs.BeginDraw;

  cvs.StretchDraw(R, wic, 128);



  {建立层}

  cvs.RenderTarget.CreateLayer(nil, iLayer); //参数1是初始大小,一般无需指定



  {为 PushLayer() 方法准备参数}

  InflateRect(R, -50, -40);

  rLayerParameters.contentBounds := R; //指定层的有效范围

//  rLayerParameters.geometricMask := nil;

  rLayerParameters.maskAntialiasMode := D2D1_ANTIALIAS_MODE_PER_PRIMITIVE;

//  rLayerParameters.maskTransform := TD2DMatrix3x2F.Identity;

  rLayerParameters.opacity := 1.0;

//  rLayerParameters.opacityBrush := nil;

  rLayerParameters.layerOptions := D2D1_LAYER_OPTIONS_NONE;



  {开始层}

  cvs.RenderTarget.PushLayer(rLayerParameters, iLayer);

  cvs.Draw(0, 0, wic);

  {结束层}

  cvs.RenderTarget.PopLayer;



  cvs.EndDraw;

  cvs.Free;

  wic.Free;

end;



procedure TForm1.FormResize(Sender: TObject);

begin

  Repaint;

end;



效果图:

Direct2D (18) : 图层之 TD2D1LayerParameters.contentBounds (图层的有效范围)

你可能感兴趣的:(parameter)