微软文档:Transforms

本篇通过官方文档学习,整理出来的demo,初始样本请先创建一个普通的desktop app。

ID2D1SolidColorBrush* m_pOriginalShapeBrush, * m_pFillBrush,* m_pTransformedShapeBrush;
ID2D1StrokeStyle* m_pStrokeStyleDash; ... LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_COMMAND:
{
int wmId = LOWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_ABOUT:
DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
}
break;
case WM_PAINT:
{
Render();
ValidateRect(hWnd, NULL);
}
break;
...
} ... void Render()
{
RECT rc;
GetClientRect(hWnd, &rc); D2D1_SIZE_U size = D2D1::SizeU(
rc.right - rc.left,
rc.bottom - rc.top
);
HRESULT hr = l->CreateHwndRenderTarget(
D2D1::RenderTargetProperties(),
D2D1::HwndRenderTargetProperties(hWnd, size),
&m_pRenderTarget
); m_pRenderTarget->BeginDraw(); m_pRenderTarget->Clear(D2D1::ColorF(D2D1::ColorF::White));
transform(); hr = m_pRenderTarget->EndDraw(); if (FAILED(hr) || hr == D2DERR_RECREATE_TARGET)
{
DiscardGraphicsResources();
}
} void DiscardGraphicsResources()
{
SafeRelease(&m_pOriginalShapeBrush);
SafeRelease(&m_pFillBrush);
SafeRelease(&m_pTransformedShapeBrush);
} void transform()
{
//旋转
HRESULT hr = m_pRenderTarget->CreateSolidColorBrush(
D2D1::ColorF(D2D1::ColorF::Black, 1.0F),
&m_pOriginalShapeBrush);
if (SUCCEEDED(hr))
{
hr = m_pRenderTarget->CreateSolidColorBrush(
D2D1::ColorF(D2D1::ColorF(0x9ACD32, 1.0f)),
&m_pFillBrush
);
}
if (SUCCEEDED(hr))
{
hr = m_pRenderTarget->CreateSolidColorBrush(
D2D1::ColorF(D2D1::ColorF::Blue, 1.0f),
&m_pTransformedShapeBrush
);
}
// Dash array for dashStyle D2D1_DASH_STYLE_CUSTOM
float dashes[] = { 1.0f, 2.0f, 2.0f, 3.0f, 2.0f, 2.0f }; // Stroke Style with Dash Style -- Custom
if (SUCCEEDED(hr))
{
hr = l->CreateStrokeStyle(
D2D1::StrokeStyleProperties(
D2D1_CAP_STYLE_FLAT,
D2D1_CAP_STYLE_FLAT,
D2D1_CAP_STYLE_ROUND,
D2D1_LINE_JOIN_MITER,
10.0f,
D2D1_DASH_STYLE_CUSTOM,
0.0f),
dashes,
ARRAYSIZE(dashes),
&m_pStrokeStyleDash
);
} // Create a rectangle.
D2D1_RECT_F rectangle_1 = D2D1::Rect(438.0f, 301.5f, 498.0f, 361.5f); // Draw the rectangle.
m_pRenderTarget->DrawRectangle(
rectangle_1,
m_pOriginalShapeBrush,
1.0f,
m_pStrokeStyleDash
); // Apply the rotation transform to the render target.
//m_pRenderTarget->SetTransform(
// D2D1::Matrix3x2F::Rotation(
// 45.0f,
// D2D1::Point2F(468.0f, 331.5f))
//); //// Fill the rectangle.
//m_pRenderTarget->FillRectangle(rectangle_1, m_pFillBrush); //// Draw the transformed rectangle.
//m_pRenderTarget->DrawRectangle(rectangle_1, m_pTransformedShapeBrush);
/*************************************************************************/
//缩放
// Create a rectangle.
D2D1_RECT_F rectangle_2 = D2D1::Rect(438.0f, 80.5f, 498.0f, 140.5f); // Draw the outline of the rectangle.
m_pRenderTarget->DrawRectangle(
rectangle_2,
m_pOriginalShapeBrush,
1.0f,
m_pStrokeStyleDash
); //// Apply the scale transform to the render target.
//m_pRenderTarget->SetTransform(
// D2D1::Matrix3x2F::Scale(
// D2D1::Size(1.3f, 1.3f),
// D2D1::Point2F(438.0f, 80.5f))
//);
//// Draw the outline of the rectangle.
//m_pRenderTarget->DrawRectangle(rectangle_2, m_pTransformedShapeBrush);
/*****************************************************************************/
//倾斜
// Create a rectangle.
D2D1_RECT_F rectangle_3 = D2D1::Rect(126.0f, 301.5f, 186.0f, 361.5f); // Draw the outline of the rectangle.
m_pRenderTarget->DrawRectangle(
rectangle_3,
m_pOriginalShapeBrush,
1.0f,
m_pStrokeStyleDash
); //// Apply the skew transform to the render target.
//m_pRenderTarget->SetTransform(
// D2D1::Matrix3x2F::Skew(
// 45.0f,
// 10.0f,
// D2D1::Point2F(126.0f, 301.5f))
//); //// Paint the interior of the rectangle.
//m_pRenderTarget->FillRectangle(rectangle_3, m_pFillBrush); //// Draw the outline of the rectangle.
//m_pRenderTarget->DrawRectangle(rectangle_3, m_pTransformedShapeBrush);
/***************************************************************************/
//平移
// Create a rectangle.
D2D1_RECT_F rectangle_4 = D2D1::Rect(126.0f, 80.5f, 186.0f, 140.5f); // Draw the outline of the rectangle.
m_pRenderTarget->DrawRectangle(
rectangle_4,
m_pOriginalShapeBrush,
1.0f,
m_pStrokeStyleDash
); // Apply the translation transform to the render target.
m_pRenderTarget->SetTransform(D2D1::Matrix3x2F::Translation(20, 10)); // Paint the interior of the rectangle.
m_pRenderTarget->FillRectangle(rectangle_4, m_pFillBrush); // Draw the outline of the rectangle.
m_pRenderTarget->DrawRectangle(rectangle_4, m_pTransformedShapeBrush); }

效果图:

注意: 对一个对象执行多个变换意味着将多个变换组合为一个。即,将每个变换矩阵的输出用作下一个的输入,从而获得所有矩阵变换的累积效果。

假设将两个变换矩阵(旋转和平移)相乘。结果是一个新的矩阵,同时执行旋转和平移功能。因为矩阵乘法不是可交换的,所以乘以平移变换的旋转变换与乘以旋转变换的平移变换是不同的。

这也就是我每应用一个效果后,都会将其注释的原因。

有专门的文档来介绍了这部分:如何将多个变换应用于对象

Direct2D 旋转篇的更多相关文章

  1. python图像处理

    Python常用处理图像的库是PIL,另外还有opencv.Matplotlib.NumPy.SciPy.skimage 详情请参考:https://www.cnblogs.com/qiaozhoul ...

  2. TGL站长关于常见问题的回复

    问题地址: http://www.thegrouplet.com/thread-112923-1-1.html 问题: 网站配有太多的模板是否影响网站加载速度 月光答复: wp不需要删除其他的模板,不 ...

  3. Direct2D教程(外篇)环境配置

    2014年世界杯首场淘汰赛马上开始了,闲着没事,整理以前的博客草稿打发时间,意外的发现这篇文章,本来是打算加入到Direct2D那个系列的,不知道为什么把它给遗漏了.环境配置,对于熟手来说,不是什么重 ...

  4. ArcGIS制图表达Representation实战篇2-河流渐变与符号旋转

    ArcGIS制图表达Representation实战篇2-河流渐变与符号旋转 by 李远祥 上一章节主要是从实战中使用规则和几何效果,如何分解制图规则.本章主要还是通过一些特殊要求如河流线宽渐变和符号 ...

  5. Direct2D教程VIII——几何(Geometry)对象的运算,本系列的终结篇

    目前博客园中成系列的Direct2D的教程有 1.万一的 Direct2D 系列,用的是Delphi 2009 2.zdd的 Direct2D 系列,用的是VS中的C++ 3.本文所在的 Direct ...

  6. WPF 精修篇 旋转 RotateTransForm

    原文:WPF 精修篇 旋转 RotateTransForm 旋转 RotateTransform Angle 角度 CenterY ,CenterX  中心点位置 和缩小一样 左侧 和右侧 做了对比 ...

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

    原文:Direct2D 第6篇 绘制多种风格的线条 上图是使用Direct2D绘制的线条,Direct2D在效率上比GDI/GDI+要快几倍,GDI/GDI+绘图是出了名的"慢", ...

  8. Direct2D 第5篇 绘制图像

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

  9. Direct2D 第4篇 渐变画刷

    原文:Direct2D 第4篇 渐变画刷 #include <windows.h> #include <d2d1.h> #include <d2d1helper.h> ...

  10. Direct2D 第3篇 绘制文字

    原文:Direct2D 第3篇 绘制文字 #include <windows.h> #include <d2d1.h> #include <d2d1helper.h> ...

随机推荐

  1. [转帖]全表扫描却产生大量db file sequential read一例

    老熊 Oracle性能优化 2012-05-23 开发人员在进行新系统上线前的数据校验测试时,发现一条手工执行的SQL执行了超过1小时还没有返回结果.SQL很简单: SELECT * FROM MOB ...

  2. [转帖]第七篇:双管齐下,JVM内部优化与JVM性能调优

    文章目录 一.前言 二.编译时优化 2.1 Javac编译器 2.2 Java语法糖 2.2.1 泛型和泛型擦除 2.2.2 自动装箱.自动拆箱.遍历循环 2.2.3 条件编译 三.运行时优化(核心: ...

  3. [转帖]Linux-文本处理三剑客grep详解

    https://developer.aliyun.com/article/885611?spm=a2c6h.24874632.expert-profile.311.7c46cfe9h5DxWK 简介: ...

  4. [转帖]将nginx.conf文件的内容拆分成多个

    nginx的如果有多个server模块都配置在同一个nginx.conf文件会显得比较臃肿,后续维护起来也会比较困难,所以可以将内容写入到多个配置文件中然后在nginx.conf文件中通过includ ...

  5. 一个简单的监控java进程获取日志的办法

    公司里面一个长时间运行的环境会出现问题, 这边简单写了一个脚本自动获取日志信息 脚本如下 注意 我的path 其实就是复用的 我们应用里面的jdk  剩下的就非常简单了. 每个日志都自动打包 并且移除 ...

  6. Springboot 内嵌Tomcat 的http连接池与thread的关系

    前言 最近看了很多tcp/ip 连接以及 IO相关的文章,但是依旧对数据库连接池等的部分不是很清楚, 所以这里仅是简单描述一下tomcat对应的http连接池数量的情况,不考虑与数据库的连接池的情况. ...

  7. 隐私集合求交(PSI)协议研究综述

    摘要 隐私集合求交(PSI)是安全多方计算(MPC)中的一种密码学技术,它允许参与计算的双方,在不获取对方额外信息(除交集外的其它信息)的基础上,计算出双方数据的交集.隐私集合求交在数据共享,广告转化 ...

  8. 人均瑞数系列,瑞数 4 代 JS 逆向分析

    声明 本文章中所有内容仅供学习交流使用,不用于其他任何目的,不提供完整代码,抓包内容.敏感网址.数据接口等均已做脱敏处理,严禁用于商业用途和非法用途,否则由此产生的一切后果均与作者无关! 本文章未经许 ...

  9. 开源项目01--WTM

    一.项目名称:WTM 项目所用技术栈: wtm mvvm mvc aspnetcore dotnetcore react vue layui layui-admin element-ui ncc等 项 ...

  10. k8s 中的网络

    k8s 中的网络模型 CNI 网络插件 CNI 的设计思想 k8s 中的三层网络 Flannel 的 host-gw Calico 参考 k8s 中的网络模型 CNI 网络插件 docker 容器的网 ...