2025年PB像素转pbu的两种方法

PB像素转pbu的两种方法像素转 pbu 的两种方法 一 像素转 pbu 的计算方法 int ConvertPBU int nValue int nType static int tmHeight 0 static int tmAveCharWid 0 static int nLogPixelsX 0 static int nLogPixelsY 0

大家好,我是讯享网,很高兴认识大家。

像素转pbu的两种方法:

/一、像素转pbu的计算方法
int ConvertPBU(int nValue, int nType)
{
    static int tmHeight = 0;
    static int tmAveCharWidth = 0;
    static int nLogPixelsX = 0;
    static int nLogPixelsY = 0;


讯享网

    if (!tmHeight && !tmAveCharWidth)
    {
        HWND hWnd = GetDesktopWindow();
        HDC hdc = SysGetDC(hWnd);
        HFONT hFont = (HFONT)GetStockObject(SYSTEM_FONT);
        HFONT hOldFont = (HFONT)SelectObject(hdc, hFont);
        TEXTMETRIC tm;
        GetTextMetrics(hdc, &tm);
        tmHeight = tm.tmHeight;
        tmAveCharWidth = tm.tmAveCharWidth;
        nLogPixelsX = GetDeviceCaps(hdc, LOGPIXELSX);
        nLogPixelsY = GetDeviceCaps(hdc, LOGPIXELSY);
        SelectObject(hdc, hOldFont);
        SysReleaseDC(hWnd, hdc);
    }
    int result = 0;
    switch (nType)
    {
    case 1:
    {
        int n = nLogPixelsX;
        if (nValue < 0)
            n = -nLogPixelsX;
        result = (6144 * nValue + 7 * n) / (14 * nLogPixelsX);
    }
    break;
    case 2:
    {
        int n = nLogPixelsY;
        if (nValue < 0)
            n = -nLogPixelsY;
        result = (n + 768 * nValue) / (2 * nLogPixelsY);
    }
    break;
    case 3:
        result = ((nValue >= 0 ? 1536 : -1536) + 7 * nValue * nLogPixelsX) / 3072;
        break;
    case 4:
        result = ((nValue >= 0 ? 192 : -192) + nValue * nLogPixelsY) / 384;
        break;
    default:
        result = 0;
        break;
    }
    return result;
}

//二、直接调用PBVMxxx.dll 法
function long FN_ConvertUnits(long unitsORpixels, long type) library "pbvmxxx.dll" //这里的DLL,根据具体自己写,比如 PB9就是 pbvm90.dll,PB12.5就是 pbvm125.dll
参数说明:
1.long unitsORpixels 像素或PBU值
2.long type,转换类型。分别可以是:
int PixelsToUnitsX(int nPixels)
{
    return FN_ConvertUnits(nPixels, 1);
}
int PixelsToUnitsY(int nPixels)
{
    return FN_ConvertUnits(nPixels, 2);
}
int UnitsToPixelsX(int nUnites)
{
    return FN_ConvertUnits(nUnites, 3);
}
int UnitsToPixelsY(int nUnites)
{
    return FN_ConvertUnits(nUnites, 4);
}

小讯
上一篇 2025-03-23 17:03
下一篇 2025-02-09 12:06

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/68642.html