Direct2D教程VIII——几何(Geometry)对象的运算,本系列的终结篇
目前博客园中成系列的Direct2D的教程有
1、万一的 Direct2D 系列,用的是Delphi 2009
2、zdd的 Direct2D 系列,用的是VS中的C++
3、本文所在的 Direct2D教程 系列,用的是VS2010的Visual Basic语言(可以很方便的转为C#),基于Windows API Code Pack 1.1。
还有官方的说明文档 Direct2D ,用的是C++。
本系列的前几篇文章:
Direct2D教程II——绘制基本图形和线型(StrokeStyle)的设置详解
Direct2D教程V——位图(Bitmap)和位图笔刷(BitmapBrush)
Direct2D教程VII——变换几何(TransformedGeometry)对象
研究Direct2D已经有一段时间了。在参阅了一些相关的文章后,发现虽然Windows API Code Pack 1.1对Direct2D封装的比较好,但也有不足的地方(封装不完全)。
1、在WIC组件中,没有封装BitmapFrameEncode对象
在前文中曾介绍,WIC组件中有BitmapFrameDecode对象,负责图像数据的解码。相对应的也应该有BitmapFrameEncode对象,负责图像数据的编码。但是在Windows API Code Pack 1.1中的WIC组件中没有这个对象,仅仅在ImagingBitmap对象中提供了SaveToFile方法。该方法提供了图像数据保存到文件的途径,但是扩展性不够,没有提供不同格式的参数设置(全采用该格式的默认设置)
2、没有提供ID2D1Effect对象的封装
Direct2D提供了一些图像的特效,通过ID2D1Effect对象实现,参看 Built-in Effects 。由于没有封装ID2D1Effect对象,自然也就没法实现图像的特效了。
期待Windows API Code Pack的下个版本能弥补上面的两个不足
言归正传,接下来介绍几何(Geometry)对象的运算。
几何(Geometry)对象的运算
在前文 Direct2D教程III——几何(Geometry)对象 中介绍了几何(Geometry)对象的一些高级功能。其中一个就是两个几何(Geometry)对象的运算功能。
运算方法的原型定义
Public Sub CombineWithGeometry(inputGeometry As Direct2D1.Geometry, combineMode As Direct2D1.CombineMode, geometrySink As Direct2D1.ISimplifiedGeometrySink)
Public Sub CombineWithGeometry(inputGeometry As Direct2D1.Geometry, combineMode As Direct2D1.CombineMode, geometrySink As Direct2D1.ISimplifiedGeometrySink, flatteningTolerance As Single)
Public Sub CombineWithGeometry(inputGeometry As Direct2D1.Geometry, combineMode As Direct2D1.CombineMode, geometrySink As Direct2D1.ISimplifiedGeometrySink, flatteningTolerance As Single, inputGeometryTransform As Direct2D1.Matrix3x2F)
Public Enum CombineMode
Union = 0
Intersect = 1
Xor = 2
Exclude = 3
End Enum
该方法的几个参数的意义如下:
inputGeometry:要和本对象运算的几何对象,类型是Geometry类
combineMode:运算的类型,类型是CombineMode枚举,分别是Union(并集)、Intersect(交集)、Xor(异或,两个对象不属于对方的部分的合集)、Exclude(差集)
geometrySink:运算的结果要添加到的Sink对象,类型是ISimplifiedGeometry接口
flatteningTolerance:运算结果的精度,类型是数值,表示模拟结果的每条边的长度,值越小越精细,在可以接受的精度下,可以适当提高精度的数值
inputGeometryTransform:和本对象运算的几何对象要进行的转换(Transform),类型是Matrix3x2F,是先转换再运算
下面是个示例代码,用两个矩形对象来演示运算结果,运算的类型我们用Xor表示,其余的和这个类似
Public Class clsDirect2DSample17
Inherits clsDirect2DSample11
Public Shadows Sub Render()
If Not _renderTarget Is Nothing Then
With _renderTarget
.BeginDraw()
.Clear(New Direct2D1.ColorF(Color.Chocolate.ToArgb))
Dim BorderBrush As Direct2D1.SolidColorBrush = _renderTarget.CreateSolidColorBrush(New Direct2D1.ColorF(0, 0, 0))
Dim Bmp As Direct2D1.D2DBitmap = LoadBitmapFromFile("216.png")
Dim BmpBrush As Direct2D1.BitmapBrush = _renderTarget.CreateBitmapBrush(Bmp)
Dim R1 As Direct2D1.RectangleGeometry, R2 As Direct2D1.RectangleGeometry
R1 = _d2DFactory.CreateRectangleGeometry(New Direct2D1.RectF(30, 30, 150, 150))
R2 = _d2DFactory.CreateRectangleGeometry(New Direct2D1.RectF(60, 60, 180, 180))
Dim P As Direct2D1.PathGeometry
Dim Sink As Direct2D1.GeometrySink
P = _d2DFactory.CreatePathGeometry()
Sink = P.Open
R1.CombineWithGeometry(R2, Direct2D1.CombineMode.Xor, Sink)
Sink.Close()
.DrawGeometry(P, BorderBrush, 3)
.FillGeometry(P, BmpBrush)
.EndDraw()
End With
End If
End Sub
End Class
下面是该示例代码的效果图
故事到此似乎很完美,然而,接下来的调试彻底让我崩溃了,先看看效果图
代码和前面的代码几乎一样,仅仅是用EllipseGeometry对象替换了RectangleGeometry对象,结果出现了不可预知的错误,大大出乎我的意料。在反复检查代码后,证实不是代码的写错后,我开始怀疑Windows API Code Pack 1.1来。
RectangleGeometry对象有一个Rectangle属性,其还有Top、Left、Right、Bottom四个属性,在上文的示例代码中,这四个值分别是30、30、150、150。
同样EllipseGeometry对象有一个Ellipse属性,其有Point属性,其还有X、Y两个属性,在调试代码时发现,这两个值是0、0。这太奇怪了,正常值是100、100(我设的中心点是(100,100))。这也许是Windows API Code Pack 1.1封装EllipseGeometry对象的一个失误。导致这两个值异常,导致几何对象运算出现不可预知的错误。
遗憾的是,在几个几何对象中(RectangleGeometry、EllipseGeometry、RoundedRectangleGeometry、PathGeometry)仅仅有RectangleGeometry对象支持CombineWithGeometry方法,其余的都会出现不可预知的错误
我很喜欢Windows API Code Pack 1.1,它是微软推出的,兼容性应该是最好的。
在测试CombineWithGeometry方法后,大失所望。没有详细的测试后,就推出了。期待Windows API Code Pack 的下一个版本,本系列的教程就到此为止了。
听闻SharpDx对Direct2D封装的很好,下图是SharpDx官网的说明图
可以看出SharpDx的优势了,打算研究一段时间。再视情况而定是否写新的教程系列。
也欢迎网友提供相关的教程,谢谢!!!!!
Direct2D教程VIII——几何(Geometry)对象的运算,本系列的终结篇的更多相关文章
- Direct2D教程III——几何(Geometry)对象
目前博客园中成系列的Direct2D的教程有 1.万一的 Direct2D 系列,用的是Delphi 2009 2.zdd的 Direct2D 系列,用的是VS中的C++ 3.本文所在的 Direct ...
- SharpDX之Direct2D教程I——简单示例和Color(颜色)
研究Direct2D已经有一段时间了,也写了一个系列的文章 Direct2D ,是基于Windows API Code Pack 1.1.在前文 Direct2D教程VIII——几何(Geometry ...
- Direct2D教程VII——变换几何(TransformedGeometry)对象
目前博客园中成系列的Direct2D的教程有 1.万一的 Direct2D 系列,用的是Delphi 2009 2.zdd的 Direct2D 系列,用的是VS中的C++ 3.本文所在的 Direct ...
- Direct2D教程VI——转换(Transform)
目前博客园中成系列的Direct2D的教程有 1.万一的 Direct2D 系列,用的是Delphi 2009 2.zdd的 Direct2D 系列,用的是VS中的C++ 3.本文所在的 Direct ...
- Direct2D教程V——位图(Bitmap)和位图笔刷(BitmapBrush)
目前博客园中成系列的Direct2D的教程有 1.万一的 Direct2D 系列,用的是Delphi 2009 2.zdd的 Direct2D 系列,用的是VS中的C++ 3.本文所在的 Direct ...
- Direct2D教程IV——笔刷(Brush)对象
目前博客园中成系列的Direct2D的教程有 1.万一的 Direct2D 系列,用的是Delphi 2009 2.zdd的 Direct2D 系列,用的是VS中的C++ 3.本文所在的 Direct ...
- SharpDX之Direct2D教程II——加载位图文件和保存位图文件
本系列文章目录: SharpDX之Direct2D教程I——简单示例和Color(颜色) 绘制位图是绘制操作的不可缺少的一部分.在Direct2D中绘制位图,必须先利用WIC组件将位图加载到内存中,再 ...
- Direct2D教程II——绘制基本图形和线型(StrokeStyle)的设置详解
目前,在博客园上,相对写得比较好的两个关于Direct2D的教程系列,分别是万一的Direct2D系列和zdd的Direct2D系列.有兴趣的网友可以去看看.本系列也是介绍Direct2D的教程,是基 ...
- java程序操作Geometry对象
Geometry 空间地理对象,Oracle中存储Geometry对象的字段类型是 MDSYS.SDO_GEOMETRY,在数据库中构建Geometry对象的方法: v_pointarray MDSY ...
随机推荐
- 【shell学习笔记】curl命令总结
2014-12-16 20:34 文思海辉 =========== CURL命令总结 1. 下载 curl -o [文件名称] www.baidu.com 2. 显示 HTTP request头信息 ...
- STM32 Timer : Base Timer, Input Capture, PWM, Output Compare
http://www.cs.indiana.edu/~geobrown/book.pdf An example of a basic timer is illustrated in Figure 10 ...
- JTAG - General description of the TAP Controller states
A transition between the states only occurs on the rising edge of TCK, and each state has a differen ...
- THE TOOLS TO MANAGE YOUR DATA ACROSS CLOUDS
http://blog.grexit.com/manage-data-across-clouds/ That the average small business uses a cloud servi ...
- ThinkPHP 模型方法 setInc() 和 setDec() 使用详解
对于数字字段的加减,可以直接使用 setInc() 与 setDec() 方法 ThinkPHP 内置了对统计数据(数字字段)的更新方法: setInc():将数字字段值增加 setDec():将数字 ...
- rcp(插件开发)插件B需要引用插件A中的jar包-如何处理依赖关系
如果插件B需要引用插件A中的jar 通常需要以下几步: 1.插件B要依赖插件A 2.在插件B的build path中添加插件A的jar包 3.插件A的runtime导出插件B中使用jar的packag ...
- Embarcadero RAD Studio XE5
英巴卡迪诺 RAD Studio XE是终极应用程序开发套件,能以最快速方式为Windows.Mac OS X. .NET. PHP. Web和移动设备可视化开发数据丰富.界面美观的跨平台应用程序.R ...
- 网站性能工具-YSlow的23个规则-网站性能优化
1. 减少HTTP请求次数 合并图片.CSS.JS,改进首次访问用户等待时间. 2. 使用CDN 就近缓存==>智能路由==>负载均衡==>WSA全站动态加速 3. 避免空的src和 ...
- lufylegend:图形变形3
面来看看drawtriangles函数的扩展.利用drawtriangles函数来实现一个旋转的3D地球,效果如下 因为lufylegend1.5.0版的drawtriangles函数有个bug,所以 ...
- How can i use iptables on centos 7?
I installed CentOS 7 with minimal configuration (os + dev tools). I am trying to open 80 port for ht ...