【发布时间】:2020-01-02 11:17:56
【问题描述】:
我正在尝试获取 Direct2D 位图的大小并立即崩溃。
// props and target etc all set up beforehand.
CComPtr<ID2D1Bitmap> &b;
target->CreateBitmap(D2D1::SizeU(1024,1024), frame.p_data, 1024* 4, &props, &b));
D2D_SIZE_U sz = b->GetPixelSize(); // Crashes here.
使用位图的所有其他操作(包括绘制它)都可以正常工作。它只是返回似乎是问题的大小。
根据 Rudy V 这样的文章,我怀疑它与 C++Builder 2010 以及 COM 函数如何返回 64 位结构有些不兼容。 http://rvelthuis.de/articles/articles-convert.html
GetPixelSize 的 Delphi 声明如下所示:(来自 D2D1.pas)
// Returns the size of the bitmap in resolution dependent units, (pixels).
procedure GetPixelSize(out pixelSize: TD2D1SizeU); stdcall;
...在 D2D1.h 中是
//
// Returns the size of the bitmap in resolution dependent units, (pixels).
//
STDMETHOD_(D2D1_SIZE_U, GetPixelSize)(
) CONST PURE;
我可以在不重写 D2D 标头的情况下解决此问题吗?
欢迎所有建议 - 除了从 C++Builder 2010 升级,这是一项比我目前准备好的任务更多的任务。
【问题讨论】:
-
您可以在自己的代码中复制
ID2D1Bitmap,然后重新声明其GetPixelSize(),通过输出引用参数返回D2D_SIZE_U,就像Delphi代码一样。跨度> -
@RemyLebeau 谢谢。经过一些测试后,我意识到拥有“固定”d2d1.h 的本地副本可能是最简单的方法。
STDMETHOD_(void, GetPixelSize)( __out D2D1_SIZE_U* size ) CONST PURE;
标签: com direct2d c++builder-2010