简体   繁体   English

IDWriteGdiInterop :: CreateBitmapRenderTarget失败

[英]IDWriteGdiInterop::CreateBitmapRenderTarget failing

I have an application which renders glyphs to a printer device context. 我有一个将字形呈现到打印机设备上下文的应用程序。 Earlier, it used GDI and it worked fine. 之前,它使用GDI,并且运行良好。 But now, I'm trying to use Directwrite instead. 但是现在,我正在尝试使用Directwrite。

I've changed the existing ExtTextOut call and used IDWriteTextLayout::Draw function. 我已经更改了现有的ExtTextOut调用,并使用了IDWriteTextLayout :: Draw函数。

I need to pass an object implementing IDWriteTextRenderer interface in the draw function. 我需要在draw函数中传递一个实现IDWriteTextRenderer接口的对象。

I've implemented the DrawGlyphRun callback in IDWriteTextRenderer interface using a call to IDWriteBitmapRenderTarget:: DrawGlyphRun. 我已通过调用IDWriteBitmapRenderTarget :: DrawGlyphRun在IDWriteTextRenderer接口中实现了DrawGlyphRun回调。 So, I need to create a IDWriteBitmapRenderTarget object. 因此,我需要创建一个IDWriteBitmapRenderTarget对象。

I have the following code : 我有以下代码:

IDWriteFactory* pDWriteFactory = NULL;
IDWriteGdiInterop* pGdiInterop = NULL;
IDWriteTextLayout* pTextLayout = NULL;
IDWriteBitmapRenderTarget* pBitmapRenderTarget = NULL;
IDWriteRenderingParams* pRenderingParams = NULL;

hr = DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED,
    __uuidof(IDWriteFactory), reinterpret_cast<IUnknown**>(&pDWriteFactory));

if (!SUCCEEDED(hr))
    pDWriteFactory = 0;
else
{
    hr = pDWriteFactory->GetGdiInterop(&pGdiInterop);
    if (!SUCCEEDED(hr))
        pGdiInterop = 0;
}

hr = pGdiInterop->CreateBitmapRenderTarget((HDC)hDC, someWidth, someHeight, &pBitmapRenderTarget);

The device context hDC is being passed by a function in another dll. 设备上下文hDC由另一个dll中的函数传递。

Result: hr=E_FAIL 结果:hr = E_FAIL

Maybe I'm missing out on something very basic, but I have little knowledge of device contexts and I'm new to DirectWrite. 也许我错过了一些非常基本的知识,但是我对设备上下文了解不多,并且是DirectWrite的新手。 I need to know why the same HDC structure which is compatible with a ExtTextOut call is not being compatible with DirectWrite. 我需要知道为什么与ExtTextOut调用兼容的同一HDC结构与DirectWrite不兼容。

Also, since the HDC field is optional, if I pass NULL, it succeeds but nothing gets rendered by the draw function. 另外,由于HDC字段是可选的,因此如果我传递NULL,则它会成功,但是draw函数不会渲染任何内容。 What does passing NULL signify ? 传递NULL表示什么?

First make sure hDC is a valid memory device context, memory part is important. 首先确保hDC是有效的内存设备上下文,内存部分很重要。 NULL argument means that target creates its own context compatible with screen/desktop. NULL参数表示目标创建自己的与屏幕/桌面兼容的上下文。 In any case nothing will be rendered automatically, you need to blit yourself from HDC returned by GetMemoryDC to your context, in other words target draws to this memory DC only, and what you do next is up to you. 无论如何,什么都不会自动呈现,您需要从GetMemoryDC返回到上下文的HDC中GetMemoryDC自己,换句话说,目标仅吸引到此内存DC,接下来您要做什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM