其他分享
首页 > 其他分享> > Direct2D (13) : 画刷之 ID2D1BitmapBrush

Direct2D (13) : 画刷之 ID2D1BitmapBrush

作者:互联网

Direct2D (13) : 画刷之 ID2D1BitmapBrush


{相关结构}
TD2D1BitmapBrushProperties = record
  extendModeX: D2D1_EXTEND_MODE;                     //三个可选值分别是:0(延伸)、1(换行)、2(镜像)
  extendModeY: D2D1_EXTEND_MODE;                     //同上
  interpolationMode: D2D1_BITMAP_INTERPOLATION_MODE; //拉伸图像时的差值算法:0(高速低质)、1(高质低速)
end;


测试代码:

uses Direct2D, D2D1;

procedure TForm1.FormPaint(Sender: TObject);
var
  cvs: TDirect2DCanvas;
  iBrush: ID2D1BitmapBrush;
  rBBP: TD2D1BitmapBrushProperties;
  R: TRect;
  bit: TBitmap;
begin
  bit := TBitmap.Create;
  bit.LoadFromFile('C:\Temp\Test.bmp');

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

  rBBP.extendModeX := D2D1_EXTEND_MODE_MIRROR;
  rBBP.extendModeY := D2D1_EXTEND_MODE_WRAP;
  rBBP.interpolationMode := D2D1_BITMAP_INTERPOLATION_MODE_LINEAR;
  cvs.RenderTarget.CreateBitmapBrush(cvs.CreateBitmap(bit), @rBBP, nil, iBrush);
  cvs.Brush.Handle := iBrush;
  //cvs.Brush.Bitmap := bit;  //如果是简单平铺,可以用这句代替上面五行

  cvs.Pen.Width := 0;
  cvs.BeginDraw;
  cvs.Rectangle(R);
  cvs.EndDraw;
  cvs.Free;
  bit.Free;
end;

procedure TForm1.FormResize(Sender: TObject);
begin
  Repaint;
end;


效果图:

o_201104023.png

posted on 2011-04-02 17:16  万一  阅读(1993)  评论(2)  编辑  收藏

标签:ID2D1BitmapBrush,13,画刷,EXTEND,cvs,rBBP,D2D1,MODE,bit
来源: https://blog.51cto.com/u_14617575/2745412