Direct2D 第6篇 绘制多种风格的线条

原文:Direct2D 第6篇 绘制多种风格的线条

上图是使用Direct2D绘制的线条,Direct2D在效率上比GDI/GDI+要快几倍,GDI/GDI+绘图是出了名的“慢”,不过Direct2D的绘制线条代码,要比GDI/GDI+要繁锁一些。

1.首先,初始化Direct2D(可以参考?http://blog.csdn.net/ubuntu_ai/article/details/50365536 )

2.创建线条的风格实例 ?ID2D1StrokeStyle,以下函数CreateStrokeStyle是创建ID2D1StrokeStyle的接口,它的声明大致如下:

virtual HRESULT CreateStrokeStyle(
  const D2D1_STROKE_STYLE_PROPERTIES *strokeStyleProperties,
  const FLOAT *dashes,
  UINT dashesCount,
  ID2D1StrokeStyle **strokeStyle
);

你可以这样创建一个ID2D1StrokeStyle实例

ID2D1StrokeStyle * g_stroke_style; // 声明线条风格接口
g_pD2DFactory->CreateStrokeStyle(D2D1::StrokeStyleProperties(
				D2D1_CAP_STYLE_ROUND,
				D2D1_CAP_STYLE_ROUND,
				D2D1_CAP_STYLE_ROUND,
				D2D1_LINE_JOIN_MITER,
				1.0f,
				D2D1_DASH_STYLE_SOLID, // 有多种风格可以设置(dash,dot....)
				10.0f),
			NULL,
			0,
			&g_stroke_style);

3. 绘制线条

在你的绘制函数中写下以下代码,此处brush我没有创建,不懂如何创建的可以参考 <a target=_blank href="http://blog.csdn.net/ubuntu_ai/article/details/50365818">点击打开链接</a>  http://blog.csdn.net/ubuntu_ai/article/details/50365818
D2D1_POINT_2F p1={20.0f, 20.0f};
D2D1_POINT_2F p2={600.0f, 20.0f};
g_pD2DHwndRenderTarget->DrawLine(p1, p2, brush, 3.0f, g_stroke_style);

4.释放你的资源

前面你创建了g_stroke_style,在Direct2D中,几乎所有创建的资源都需要释放,否则后果会导致内存泄漏(后果会怎样我也不知道)

这样释放你的资源

#define SafeRelease(p) ? ?if(p){ p->Release(); p = NULL; }

SafeRelease(g_stroke_style)

?作者已经用VS编译一个实例,存放在我的【资源】当中,有必须的可以前往下载

点击打开链接? ? ?http://download.csdn.net/detail/ubuntu_ai/9386783

原文地址:https://www.cnblogs.com/lonelyxmas/p/10823172.html

时间: 2024-08-06 20:17:59

Direct2D 第6篇 绘制多种风格的线条的相关文章

Direct2D 第3篇 绘制文字

原文:Direct2D 第3篇 绘制文字 #include <windows.h> #include <d2d1.h> #include <d2d1helper.h> #include <dwrite.h> #pragma comment(lib, "dwrite.lib") #pragma comment(lib, "d2d1.lib") HINSTANCE g_hinst; HWND g_hwnd; ID2D1Fa

Direct2D 第2篇 绘制椭圆

原文:Direct2D 第2篇 绘制椭圆 #include <windows.h> #include <d2d1.h> #include <d2d1helper.h> #include <dwrite.h> #pragma comment(lib, "dwrite.lib") #pragma comment(lib, "d2d1.lib") HINSTANCE g_hinst; HWND g_hwnd; ID2D1Fa

Direct2D 第5篇 绘制图像

原文:Direct2D 第5篇 绘制图像 我加载的图像是一张透明底PNG图像,背景使用渐变的绿色画刷 #include <windows.h> #include <d2d1.h> #include <d2d1helper.h> #include <dwrite.h> #pragma comment(lib, "dwrite.lib") #pragma comment(lib, "d2d1.lib") #include

PPT分享第01季-226套多种风格模板

包含商务欧美扁平风.唯美文艺IOS风.互联网计划书风.扁平风手绘风卡通风 .中国风等多种风格 下面是部分模板截图: 下面是下载地址 原文地址:https://blog.51cto.com/12130120/2373946

Direct2D 第1篇 最简单的D2D程序

原文:Direct2D 第1篇 最简单的D2D程序 编译之前,得先安装DirectX SDK #include <windows.h> #include <d2d1.h> #include <d2d1helper.h> #include <dwrite.h> #pragma comment(lib, "dwrite.lib") #pragma comment(lib, "d2d1.lib") static HINSTA

Direct2D 第4篇 渐变画刷

原文:Direct2D 第4篇 渐变画刷 #include <windows.h> #include <d2d1.h> #include <d2d1helper.h> #include <dwrite.h> #pragma comment(lib, "dwrite.lib") #pragma comment(lib, "d2d1.lib") HINSTANCE g_hinst; HWND g_hwnd; ID2D1Fa

C# winform如何清除由Graphics类绘制出来的所有线条或图形

在C#winform应用程序中,可以用GDI绘制出线条或图形. 1.在主窗体上绘制线条或图形 using (Graphics g = this.CreateGraphics())      {            g.DrawLine(Pens.Blue, new Point(10, 10), new Point(100, 100));      } 2.在指定的容器上绘制线条或图形,如在panel1上绘制 using (Graphics g = this.panel1.CreateGraph

用matplotlib绘制漫画风格的图表

自从有了计算机,便很少有人手工绘制图表了.计算机绘制出的图表横平竖直,可以随意使用各种颜色,也完全不用担心画错需要重来的问题. 但有没有一种感觉,看多了工整的图表,变得有些审美疲劳.在各行各业逐渐过渡到计算机绘图的时候,有些人开始怀念起手绘来,只不过用全新的方式——触控板来进行手绘. 1 用Python的maplotlib包绘图 平时喜欢倒腾一些数据,没少画各种图,最常用的是Python的Matplotlib包,简单的几行代码,便可以绘出精美的图来.matplotlib包模仿了MATLAB的绘图

题外:分类篇(音乐风格分类)基于BP神经网络

语音特征参数MFCC的提取及识别 (2012-09-07 20:24:03) 转载▼ 耳蜗实质上相当于一个滤波器组,耳蜗的滤波作用是在对数频率尺度上进行的,在1000HZ下,人耳的感知能力与频率成线性关系:而在1000HZ以上,人耳的感知能力与频率不构成线性关系,而更偏向于对数关系,这就使得人耳对低频信号比高频信号更敏感.Mel频率的提出是为了方便人耳对不同频率语音的感知特性的研究.频率与Mel频率的转换公式为: MFCC在一定程度上模拟了人耳对语音的处理特点,应用了人耳听觉感知方面的研究成果,