Windows图像处理组件 - Direct2D的C ++ - 绘图,保存 [英] Windows Imaging Component - Direct2D C++ - Drawing, Saving

查看:1776
本文介绍了Windows图像处理组件 - Direct2D的C ++ - 绘图,保存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Windows图像处理组件(WIC),我想要做我的Windows桌面应用程序(的Direct2D / C ++与Windows 7 SP1 - 的Visual Studio 2013)以下

Using Windows Image Component (WIC), I want to do the following for my windows desktop application (Direct2D/C++ with Windows 7 SP1 - Visual Studio 2013)


  1. 选择任何类型的RenderTarget(HWND的Direct2D /位图/ WICBitmap -
    等)绘制

  1. Choose any type of RenderTarget (Direct2D Hwnd/Bitmap/WICBitmap - etc) for drawing

创建一个空的位图(D2D1Bitmap或IWICBitmap -
适用者为准)

Create a empty bitmap (D2D1Bitmap or IWICBitmap - whichever applicable)

开始抽奖 - 填充颜色,画一些线条和椭圆 -
抽签结束==>(所有的位图)

Begin draw - Fill colour, draw some lines and ellipses - End draw ==> (All in the Bitmap)

在一定的时间点,我需要
保存位图的绘制的内容作为图像在我的电脑

At some point of time, I need to save the drawn content in the bitmap as an image in my computer

放置在X1位图,Y1(左上 - 的xy坐标)和X2,Y2
(右下 - XY坐标)渲染目标的。由于
窗口的空间的其余部分将通过工具栏被使用。

Place the bitmap in the x1,y1 (top left - xy coordinates) and x2,y2 (bottom right - xy coordinates) of the render target. Because the rest of the space of the window would be used by toolbar.

我如何做到这一点使用C ++ / Direct2D的?

How do I achieve this using C++/Direct2D?

GDI + code为我的功能:

Bitmap* pBmp = NULL; //create null or empty bitmap
Graphics* pGrBuf = NULL; //initialise graphics to null

pBmp = new Bitmap((INT)rectClient.Width, (INT)rectClient.Height);
pGrBuf = new Graphics(pBmp);

在这个图形,我总能画直线,矩形等。

On this Graphics, I could always draw Lines, Rectangles, etc..

pGrBuf.DrawRectangle(....)
pGrBuf.DrawLine(...)

在结束时,用于实现点编号5

In the end, for achieving point number 5

//leave some space (30, 30 in xy co-ordinates) for putting the toolbox in the top
pGrBuf.DrawImage(m_pBmp, 30.0f, 30.0f);

有关点4 code故意省略。

The code for point 4 is intentionally omitted.

推荐答案

这个问题有一个简单,明确的答案,但有一些细节,你应该(重新)考虑。

The question have a simple, unambiguous answer, but there are some details that you should (re)consider.

Direct2D的也不是万能的框架,将很容易超越别人。这不是很清楚什么是你的图纸约而什么他们的目的,但也有在那里的Direct2D使用不是很合适的情况下。如果用D2D取代GDI(+),你的一些痛苦的将是:

Direct2D is not a panacea framework that will easily outperform others. It's not very clear what are your drawings about and whats their purpose, but there are cases where Direct2D usage is not very appropriate. If you replace GDI(+) with D2D, some of your sufferings will be:


  • (officialy)有限的操作系统支持,按照DirectX版本和/或将要使用的功能。你将不得不忘记Windows XP中,(很可能),Windows Vista和(可能更少)的Windows 7

  • 的性能(相对于GDI + GDI)并不总是更大。主要依赖从方式使用D2D的目的。有些情况下D2D有表现很差(通常是错误使用或误解的概念)的情况。

但同时,Direct2D中能够提供的优势是数不胜数。

But also, the advantages that Direct2D could provide are countless.

粗略地说,Direct2D的是什么,但周围的Direct3D的包装。它用了DirectX 10引入和它的使用是非常相似的GDI(+)。但与DirectX 11(1)中,Direct2D的原则进行了改变,现在其更D3D一样。它增加了另一个办法和降旧的。这可能是一开始有点混乱。混乱,也因为在网络的所有教程,文章和任何D2D资源(包括MSDN)是在D2D版本之间的混淆。其中有些是旧版本,并推荐一件事(的做法),其他描述新版本。

Roughly said, Direct2D is nothing but a wrapper around Direct3D. It was introduced with the DirectX 10 and its usage was very similar to GDI(+). But with DirectX 11(1), the Direct2D "principles" were changed and now its more D3D-like. It adds another approaches and drops old ones. It could be a little bit confusing at first. Confusing, also because all the tutorials, articles and whatever D2D resources (including MSDN) in the web are mixed up between the D2D versions. Some of them are for the old version and recommend one thing (approach), other describe the new version.

不管怎样,我建议新的版本 - 即Direct2D的11.1

Anyway, I recommend the new version - ie Direct2D 11.1.

要你的问题...


  1. 在的RenderTarget是从老D2D的概念。新的一个是DeviceContext

  2. 的DeviceContext有一个目标可能是一个D2D1Bitmap(1) - 屏幕外的,一个交换链的后台缓冲

  3. 最典型的绘图方法是调用DeviceContext.BeginScene --- DeviceContext.EndScene块内的绘图功能。绘图功能是非常相似的GDI(+)的。

  4. 有几种方法可以做到这一点。你可以用WIC的帮助下做到这一点。您也可以你D2D1Bitmap数据复制到一个或DIBBitmap你甚至可以(重新)绘制它通过GDI环境。

  5. 有一个功能DeviceContext.DrawImage,但你会做的方式取决于许多因素。例如,你可以有两个位图,被绘制在两个不同的HWND(一个工具栏,另一个用于其他图)。

下面有一些资源,可以帮助你:

Here are some resources that could help you:

  • What is Direct2D for
  • Drawing a rectangle with Direct2D
  • Very well explained guide about migrating to Direct2D 1.1
  • Answer to another question here, related to Direct2D, but explains in short the way you should draw to a HWnd

这篇关于Windows图像处理组件 - Direct2D的C ++ - 绘图,保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆