将给定的字符文字保存成.bmpd的图象!~~~在此谢过了!!~~~

解决方案 »

  1.   

    {
        CString strText = _T("TEXT");
        HDC hdc = ::GetDC(NULL);
        ASSERT(hdc);
        CRect rect(0, 0, 0, 0);
        int iReturn;
       
        ::DrawText(hdc, strText, strText.GetLength(), &rect, DT_CALCRECT);    HBITMAP hbitmap = ::CreateCompatibleBitmap(hdc, rect.Width(), rect.Height());    HDC hMemDC = ::CreateCompatibleDC(hdc);
        hbitmap = (HBITMAP)::SelectObject(hMemDC, hbitmap);    ::PatBlt(hMemDC, rect.left, rect.top, rect.right, rect.bottom, WHITENESS);
        ::SetBkMode(hMemDC, TRANSPARENT);
        ::DrawText(hMemDC, strText, strText.GetLength(), &rect, DT_LEFT | DT_BOTTOM);
       
        hbitmap = (HBITMAP)::SelectObject(hMemDC, hbitmap);
        ::DeleteDC(hMemDC);    long lSizeImage = rect.Height() * (4 * (rect.Width()*24 + 31)/32);    BITMAPINFOHEADER bmih;
        BITMAPFILEHEADER bmfh;
       
        ::memset(&bmih, 0, sizeof(bmih));
        bmih.biSize = sizeof(BITMAPINFOHEADER);
        bmih.biPlanes = 1;
        bmih.biBitCount = 24;
        bmih.biWidth = rect.Width();
        bmih.biHeight = rect.Height();
        bmih.biCompression = BI_RGB;      
        PBYTE pbits = new BYTE[lSizeImage];
        ASSERT(pbits);    iReturn = ::GetDIBits(hdc, hbitmap, 0, rect.Height(), pbits, (LPBITMAPINFO)&bmih, DIB_RGB_COLORS);
        ::ReleaseDC(NULL, hdc);
        ::DeleteObject(hbitmap);    long lFileSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + lSizeImage;    bmfh.bfType        = *(WORD*)"BM";
        bmfh.bfSize        = lFileSize;
        bmfh.bfOffBits    = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
        bmfh.bfReserved1 = 0;
        bmfh.bfReserved2 = 0;    HANDLE hFile = ::CreateFile(_T("c:\\TEXT.bmp"), GENERIC_WRITE, 0, NULL,CREATE_ALWAYS ,FILE_ATTRIBUTE_NORMAL, NULL);
        ASSERT(hFile != INVALID_HANDLE_VALUE);    DWORD dwNum;
        BOOL  bReturn;
        bReturn = ::WriteFile(hFile, &bmfh, sizeof(bmfh), &dwNum, NULL);
        bReturn = ::WriteFile(hFile, &bmih, sizeof(bmih), &dwNum, NULL);
        bReturn = ::WriteFile(hFile, pbits, lSizeImage, &dwNum, NULL);    delete []pbits;
        CloseHandle(hFile);   
    }
      

  2.   

    这是256到24位的,自己看看翻过了用ConvertMaskToAlpha( DWORD *pdwDestData,
        const BYTE *pByMaskeData )
    {
        for ( DWORD i = DWORD_ZERO; i < m_dwPixelNum / NUM_8BIT; i++ )
        {
            std::bitset<NUM_8BIT> bitMask( *( pByMaskeData + i ) );
            for ( UINT j = UINT_ZERO; j < NUM_8BIT; j++ )
            {
                if ( true == bitMask[ UINT_SEVEN - j ] )
                {
                    *( pdwDestData + i * NUM_8BIT + j ) &= ALPHA_0;
                }
                else
                {
                    *( pdwDestData + i * NUM_8BIT + j ) |= ALPHA_255;
                }
            }
        }
    }
      

  3.   

    for ( DWORD i = DWORD_ZERO; i < m_dwPixelNum; i++ )
        {        nPixelData = pByImageData[nRGBGuadSize+i];
            pdwTempPixelData[i] = ( BYTE_FF << NUM_24BIT )
                + ( ByRGEGuad[nPixelData].rgbRed << NUM_16BIT )
                + ( ByRGEGuad[nPixelData].rgbGreen << NUM_8BIT )
                + ByRGEGuad[nPixelData].rgbBlue;
            nPixelData = DWORD_ZERO;
        }
      

  4.   

    为什么我用CBitmap创建了一张单色位图黑背景白色字体的,但是保存的时候却只有黑色背景,而没有白色的字??请大侠指教!!