gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 03:02:33 27 4
gpt4 key购买 nike

我正在尝试使用 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com