c++ - 为什么 Graphics::DrawString 绘制杂项字符?

标签 c++ gdi+ gdi

我正在尝试使用 GDI+ 将文本绘制到图像上,但是,我注意到 DrawString(...) 中有我的文本,后面跟着几个杂项字符(看起来可能是日语)。这些字符仅在使用 DrawString 时出现,我通过将位图保存到文件中注意到了这一点。有谁知道这可能是什么原因造成的?我的 GDI 代码是

#include <windows.h>
#include <Gdiplus.h>
using namespace Gdiplus;

int main(void)
{
    GdiplusStartupInput gdiplusStartupInput;
    ULONG_PTR           gdiplusToken;
    GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

    Font* myFont = new Font(L"Times New Roman", 10);
    Bitmap* characterBitmap = new Bitmap(256, 256, PixelFormat32bppARGB);
    Graphics* g = new Graphics(characterBitmap);

    g->Clear(Color::Transparent);

    SolidBrush* myBrush = new SolidBrush(Color::Black);
    g->DrawString(L"TEST", 48, myFont, PointF(0, 0), myBrush);

    CLSID pngClsid;
    GetEncoderClsid(L"image/png", &pngClsid);
    characterBitmap->Save(L"test.png",  &pngClsid, NULL);

    GdiplusShutdown(gdiplusToken);

    return 0;
}

最佳答案

您应该阅读 Graphics::DrawString 的文档功能。

第二个参数应该是:

Integer that specifies the number of characters in the string array. The length parameter can be set to –1 if the string is null terminated.

关于c++ - 为什么 Graphics::DrawString 绘制杂项字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10067657/

相关文章:

c++ - 自动和复制构造函数 : what's wrong?

c++ - 将 GLSL 转换为 C++ float/vec3?

c++ - Windows用directx画东西不是更好吗?

C++ OOP - 数组(矩阵)乘法、删除对象

c++ - 发送儿子而不是父亲的对象

c# - 刷新表单后如何保留绘制的形状?

bitmap - 准确映射由 Graphics.DrawImage 缩放的像素

c# - 在 GDI+ 中调整大小时出现 Ghost-borders ('ringing' )

c++ - 沉浸式全屏模式之上的透明窗口

c - 如果你释放一个不干净的设备上下文会发生什么?