GetGlyphOutline获取到字体轮廓的信息,我怎么将这个信息转换为bitbmp图保存在本地

月夜暗留香1 2016-11-21 02:40:29
我要做的是从一个ttf文件读取字符的轮廓然后保存为图片
...全文
283 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2016-11-22
  • 打赏
  • 举报
回复
FillPath The FillPath function closes any open figures in the current path and fills the path's interior by using the current brush and polygon-filling mode. BOOL FillPath( HDC hdc // handle to device context ); Parameters hdc Handle to a device context (DC) that contains a valid path. Return Values If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. Windows NT: To get extended error information, callGetLastError. GetLastError may return one of the following error codes: ERROR_CAN_NOT_COMPLETE ERROR_INVALID_PARAMETER ERROR_NOT_ENOUGH_MEMORY Remarks After its interior is filled, the path is discarded from the DC identified by the hdc parameter. QuickInfo Windows NT: Requires version 3.1 or later. Windows: Requires Windows 95 or later. Windows CE: Unsupported. Header: Declared in wingdi.h. Import Library: Use gdi32.lib. See Also Paths Overview, Path Functions, BeginPath, SetPolyFillMode, StrokeAndFillPath, StrokePath
赵4老师 2016-11-22
  • 打赏
  • 举报
回复
C源代码:显示指定字符在指定字体中对应的由直线段和Bezier曲线段组成的笔划形状的命令行工具FontPath http://download.csdn.net/detail/zhao4zhong1/6588091
schlafenhamster 2016-11-22
  • 打赏
  • 举报
回复

vc6 win7
月夜暗留香1 2016-11-22
  • 打赏
  • 举报
回复
引用 7 楼 schlafenhamster 的回复:
"这个不行,汉字会崩溃" vc6 ;ansi
vs2012 Unicode编码
schlafenhamster 2016-11-22
  • 打赏
  • 举报
回复
"这个不行,汉字会崩溃" vc6 ;ansi
月夜暗留香1 2016-11-22
  • 打赏
  • 举报
回复
感谢赵4老师、schlafenhamster两位大神的帮助,问题已解决。 结贴了
月夜暗留香1 2016-11-21
  • 打赏
  • 举报
回复
引用 2 楼 zhao4zhong1 的回复:
仅供参考:
#pragma comment(lib,"gdi32")
#include <windows.h>
#include <stdio.h>

int main() {
    const DWORD uWidth = 18 + 17 * 256, uHeight = 18 + 17 * 128;

    PBITMAPINFO pbmi = (PBITMAPINFO) LocalAlloc (LPTR, sizeof (BITMAPINFOHEADER) + sizeof (RGBQUAD) * 2);
    pbmi->bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
    pbmi->bmiHeader.biWidth = uWidth;
    pbmi->bmiHeader.biHeight = uHeight;
    pbmi->bmiHeader.biPlanes = 1;
    pbmi->bmiHeader.biBitCount = 1;
    pbmi->bmiHeader.biSizeImage = ((uWidth + 31) & ~31) / 8 * uHeight;
    pbmi->bmiColors[0].rgbBlue = 0;
    pbmi->bmiColors[0].rgbGreen = 0;
    pbmi->bmiColors[0].rgbRed = 0;
    pbmi->bmiColors[1].rgbBlue = 255;
    pbmi->bmiColors[1].rgbGreen = 255;
    pbmi->bmiColors[1].rgbRed = 255;

    HDC hDC = CreateCompatibleDC (0);
    void * pvBits;
    HBITMAP hBitmap = CreateDIBSection (hDC, pbmi, 0, &pvBits, NULL, 0);
   
感谢赵老师的帮助 刚才那个我改好了,我想问下如果是自定义的ttf文件,里面的字形是特殊符号,比如一个圆圈里面是数字1或2一类的怎么把它保存下来
月夜暗留香1 2016-11-21
  • 打赏
  • 举报
回复
引用 3 楼 schlafenhamster 的回复:
“”TtfShow.zip“” http://download.csdn.net/detail/schlafenhamster/3652429 “显示汉字轮廓,是“http://www.cppblog.com/vczh/archive/2008/06/11/52949.html”的继续。自带2次(QuadraticBezier())和3次(CubicBezier())函数。”
这个不行,汉字会崩溃
月夜暗留香1 2016-11-21
  • 打赏
  • 举报
回复
引用 2 楼 zhao4zhong1 的回复:
仅供参考:
#pragma comment(lib,"gdi32")
#include <windows.h>
#include <stdio.h>

int main() {
    const DWORD uWidth = 18 + 17 * 256, uHeight = 18 + 17 * 128;

    PBITMAPINFO pbmi = (PBITMAPINFO) LocalAlloc (LPTR, sizeof (BITMAPINFOHEADER) + sizeof (RGBQUAD) * 2);
    pbmi->bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
    pbmi->bmiHeader.biWidth = uWidth;
    pbmi->bmiHeader.biHeight = uHeight;
    pbmi->bmiHeader.biPlanes = 1;
    pbmi->bmiHeader.biBitCount = 1;
    pbmi->bmiHeader.biSizeImage = ((uWidth + 31) & ~31) / 8 * uHeight;
   
我想要特定字的图像,你这个有点点看不懂啊,求注释
schlafenhamster 2016-11-21
  • 打赏
  • 举报
回复
“”TtfShow.zip“” http://download.csdn.net/detail/schlafenhamster/3652429 “显示汉字轮廓,是“http://www.cppblog.com/vczh/archive/2008/06/11/52949.html”的继续。自带2次(QuadraticBezier())和3次(CubicBezier())函数。”
赵4老师 2016-11-21
  • 打赏
  • 举报
回复
仅供参考:
#pragma comment(lib,"gdi32")
#include <windows.h>
#include <stdio.h>

int main() {
    const DWORD uWidth = 18 + 17 * 256, uHeight = 18 + 17 * 128;

    PBITMAPINFO pbmi = (PBITMAPINFO) LocalAlloc (LPTR, sizeof (BITMAPINFOHEADER) + sizeof (RGBQUAD) * 2);
    pbmi->bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
    pbmi->bmiHeader.biWidth = uWidth;
    pbmi->bmiHeader.biHeight = uHeight;
    pbmi->bmiHeader.biPlanes = 1;
    pbmi->bmiHeader.biBitCount = 1;
    pbmi->bmiHeader.biSizeImage = ((uWidth + 31) & ~31) / 8 * uHeight;
    pbmi->bmiColors[0].rgbBlue = 0;
    pbmi->bmiColors[0].rgbGreen = 0;
    pbmi->bmiColors[0].rgbRed = 0;
    pbmi->bmiColors[1].rgbBlue = 255;
    pbmi->bmiColors[1].rgbGreen = 255;
    pbmi->bmiColors[1].rgbRed = 255;

    HDC hDC = CreateCompatibleDC (0);
    void * pvBits;
    HBITMAP hBitmap = CreateDIBSection (hDC, pbmi, 0, &pvBits, NULL, 0);
    SelectObject (hDC, hBitmap);
    HFONT hFont = CreateFont (16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "宋体");
//  HFONT hFont = CreateFont (16, 0, 0, 0, 0, 0, 0, 0, SHIFTJIS_CHARSET, 0, 0, 0, 0, "宋体");
    SelectObject (hDC, hFont);
    BitBlt (hDC, 0, 0, uWidth, uHeight, NULL, 0, 0, WHITENESS);

    char c[4];
    int i, j;
    for (i = 128; i < 256; i++) {
        sprintf (c, "%02X", i);
        TextOut (hDC, 1, (i - 127) * 17 + 1, c, 2);
    }
    for (j = 0; j < 256; j++) {
        sprintf (c, "%02X", j);
        TextOut (hDC, (j + 1)* 17 + 1, 1, c, 2);
    }
    for (i = 128; i < 256; i++) {
        for (j = 0; j < 256; j++) {
            c[0] = (char) i;
            c[1] = (char) j;
            TextOut (hDC, (j + 1) * 17 + 1, (i - 127) * 17 + 1, c, 2);
        }
    }
    for (i = 0; i < 130; i++) {
        MoveToEx (hDC, 0, i * 17, NULL);
        LineTo (hDC, uWidth, i * 17);
    }
    for (j = 0; j < 258; j++) {
        MoveToEx (hDC, j * 17, 0, NULL);
        LineTo (hDC, j * 17, uHeight);
    }

    BITMAPFILEHEADER bmfh;
    bmfh.bfType = *(PWORD) "BM";
    bmfh.bfReserved1 = 0;
    bmfh.bfReserved2 = 0;
    bmfh.bfOffBits = sizeof (BITMAPFILEHEADER) + sizeof (BITMAPINFOHEADER) + sizeof (RGBQUAD) * 2;
    bmfh.bfSize = bmfh.bfOffBits + pbmi->bmiHeader.biSizeImage;

    HANDLE hFile = CreateFile ("goal.bmp", GENERIC_WRITE, 0, 0, CREATE_ALWAYS, 0, 0);
    if (hFile != INVALID_HANDLE_VALUE) {
        DWORD dwWritten;
        WriteFile (hFile, &bmfh, sizeof (BITMAPFILEHEADER), &dwWritten, NULL);
        WriteFile (hFile, pbmi, sizeof (BITMAPINFOHEADER) + sizeof (RGBQUAD) * 2, &dwWritten, NULL);
        WriteFile (hFile, pvBits, pbmi->bmiHeader.biSizeImage, &dwWritten, NULL);

        CloseHandle (hFile);
    }

    DeleteObject (hFont);
    DeleteObject (hBitmap);
    DeleteDC (hDC);
    LocalFree (pbmi);

    return 0;
}
月夜暗留香1 2016-11-21
  • 打赏
  • 举报
回复
没有人吗,求大神救急

19,469

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧