我正在尝试使用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;
}发布于 2012-04-09 09:16:35
您应该阅读Graphics::DrawString函数的文档。
第二个参数应该是:
整数,指定字符串数组中的字符数。如果字符串以null结尾,则length参数可以设置为-1。
https://stackoverflow.com/questions/10067657
复制相似问题