zoukankan      html  css  js  c++  java
  • Direct2D 几何计算和几何变幻

    D2D不仅可以绘制,还可以对多个几何图形对象进行空间运算。这功能应该在GIS界比较吃香。

    这些计算包括:


    写一个合并的例子:对两个圆求并集,并将绘制结果存存储到一个path中,在组成path的关节的过程中需要用sink对象。最后绘制path
    pRenderTarget->BeginDraw();
    
    	//clear screen
    	pRenderTarget->Clear(D2D1::ColorF(D2D1::ColorF::White));
    
    	//define 2 ellipse
    	const D2D1_ELLIPSE ellipse1 = Ellipse(Point2F(200,300),150,150);
    	const D2D1_ELLIPSE ellipse2 = Ellipse(Point2F(200,250),100,200);
    
    	//define ellipse geometry for compute
    	ID2D1EllipseGeometry* pEllipse1 = NULL;
    	ID2D1EllipseGeometry* pEllipse2 = NULL;
    	//define path for render the combine result
    	ID2D1PathGeometry* pPathGeo = NULL;
    	//define a path container
    	ID2D1GeometrySink* pGeometrySink = NULL;
    
    	//initialize the ellipses and path.
    	hr = pD2DFactory->CreateEllipseGeometry(ellipse1, &pEllipse1);
    	hr = pD2DFactory->CreateEllipseGeometry(ellipse2, &pEllipse2);
    	hr = pD2DFactory->CreatePathGeometry(&pPathGeo);
    
    	//begin add path
    	pPathGeo->Open(&pGeometrySink);
    	//combine the 2 ellipse and the result go into the sink
    	pEllipse1->CombineWithGeometry(pEllipse2, D2D1_COMBINE_MODE_UNION, NULL, NULL, pGeometrySink); 
    	//end add path
    	pGeometrySink->Close();
    	//draw the path
    	pRenderTarget->DrawGeometry(pPathGeo, pBlackBrush);
    
    	pRenderTarget->EndDraw();

    除此之外,D2D还支持对几何对象的变幻,包括:
    • 旋转,
    • 缩放,
    • 平移,
    可以用pRenderTarget的SetTransform来设置。

  • 相关阅读:
    文档的几何形状和滚动
    聊聊并发——生产者消费者模式
    在JavaScript中什么时候使用==是正确的?
    HTML5使用canvas画图时,图片被自动放大模糊的问题
    获取元素的几种方式
    利用jQuery和CSS实现环形进度条
    最实用、最常用的jQuery代码片段
    表格样式
    javascript常量的定义
    null 和 undefined 的区别
  • 原文地址:https://www.cnblogs.com/aukle/p/3223778.html
Copyright © 2011-2022 走看看