zoukankan      html  css  js  c++  java
  • 读取资源中的GIF文件相应像素宽高度

    代码参考了如下网页的实现:

    https://www.cnblogs.com/zy791976083/p/9921069.html

    整理成一个函数:

    BOOL GetResGifSize(long nResId, LPCTSTR name, long *lnWidth, long *lnHeight)
    {
        HRSRC hRsrc = FindResource(NULL, MAKEINTRESOURCE(nResId), name);
        if (NULL == hRsrc) {
            return FALSE;
        }
    
        DWORD dwSize = SizeofResource(NULL, hRsrc);
        HGLOBAL hGlobal = LoadResource(NULL, hRsrc);
        if (NULL == hGlobal) {
            CloseHandle(hRsrc);
            return FALSE;
        }
    
        unsigned char* pBuffer = (unsigned char*)LockResource(hGlobal);
        if (NULL == pBuffer) {
            CloseHandle(hRsrc);
            FreeResource(hGlobal);
            return FALSE;
        }
    
        //判断是否为GIF文件
        if(pBuffer[0] != 0x47 && pBuffer[1] != 0x49 && pBuffer[2] != 0x46 && pBuffer[3] != 0x38){
            return FALSE;
        }
    
        //读取宽高
        for(int i = 4; i < dwSize ; i++)
        {
            if(pBuffer[i] == 0x00 && pBuffer[i+1] == 0x2c)
            {
                *lnWidth = (pBuffer[i+7]<<8) | pBuffer[i+6];
                *lnHeight = (pBuffer[i+9]<<8) | pBuffer[i+8];
                UnlockResource(hGlobal);
                FreeResource(hGlobal);
                return TRUE;
            }
        }
    
        UnlockResource(hGlobal);
        FreeResource(hGlobal);
    
        return FALSE;
    }
  • 相关阅读:
    Nim or not Nim? hdu3032 SG值打表找规律
    Maximum 贪心
    The Super Powers
    LCM Cardinality 暴力
    Longge's problem poj2480 欧拉函数,gcd
    GCD hdu2588
    Perfect Pth Powers poj1730
    6656 Watching the Kangaroo
    yield 小用
    wpf DropDownButton 源码
  • 原文地址:https://www.cnblogs.com/eaglexmw/p/11176130.html
Copyright © 2011-2022 走看看