VC驿站

 找回密码
 加入驿站

QQ登录

只需一步,快速开始

搜索
查看: 844|回复: 2

[求助] 关bmp 位图

[复制链接]
11_avatar_middle
online_vip 发表于 2016-7-30 23:05:41 | 显示全部楼层 |阅读模式
我已经过一张图写在内存里  如果把他直接显示在控件上呢  而不通过保存存图片  再读取图片
代码如下:
BOOL CTLClinetDlg::DrawMap()
{
        //recvData  为图片数据体
        unsigned char recvData[0x241] = { 0x2C, 0x2C, 0x2C, 0x2C, 0x2C, 0x2C, 0x2D, 0x2C, 0x2C, 0x2C, 0x2C, 0x2C, 0x2C, 0x2C, 0x2F, 0xAC, 0x2D, 0x2C, 0xAC, 0x2C, 0x2C, 0x2C, 0x2D, 0x2C,
                                                     0x2D, 0x2C, 0x2C, 0x2C, 0x2C, 0x2C, 0x3B, 0xAC, 0x2C, 0x2C, 0xAC, 0x2C, 0x2C, 0x2C, 0x2C, 0x2C, 0x30, 0x2C, 0x2C, 0x2C, 0x2C, 0x2C, 0x5C, 0xF4,
                                                         0x2C, 0x2C, 0x2F, 0x2C, 0x2C, 0x2C, 0x2C, 0x2C, 0x2E, 0x2C, 0x2C, 0x2C, 0x2C, 0x2C, 0x9C, 0xEC, 0x2C, 0xAC, 0x2E, 0x2C, 0x2C, 0x2C, 0x2C, 0x2C,
                                                         0x2C, 0x2C, 0x2C, 0x2C, 0x2C, 0x2C, 0x8C, 0x2C, 0x2C, 0x2C, 0x2C, 0x2C, 0x2C, 0x2C, 0x2C, 0x2C, 0x2C, 0x30, 0x2C, 0x2C, 0x2C, 0x2C, 0xEC, 0x2C,
                                                         0x2C, 0x2C, 0x2C, 0x2C, 0x2C, 0x2C, 0x2C, 0x2C, 0x2C, 0xAC, 0x2C, 0x2D, 0x24, 0x2C, 0x0C, 0x2D, 0x2C, 0x2C, 0x2C, 0x2C, 0x2C, 0x2D, 0x2C, 0x2C,
                                                         0x2C, 0xEC, 0x2C, 0x33, 0x2A, 0x2C, 0x6C, 0x53, 0x2C, 0x2C, 0x2C, 0x2C, 0x2C, 0x2D, 0x30, 0x2C, 0x2D, 0xF8, 0x2C, 0x3B, 0x1B, 0x2C, 0x0C, 0x23,
                                                         0x2C, 0x2C, 0x24, 0x2C, 0x4B, 0xAC, 0x30, 0x2C, 0x4A, 0x8C, 0x2C, 0x4B, 0x2A, 0xAC, 0x8F, 0x8F, 0x2C, 0x2C, 0x2B, 0xAC, 0xAB, 0x14, 0x2C, 0x34,
                                                         0xAA, 0x2C, 0x2C, 0x69, 0x2B, 0x6C, 0x22, 0x2D, 0x2C, 0x2C, 0xF3, 0x1C, 0x2B, 0xB8, 0x2C, 0x34, 0x2A, 0x2C, 0x2C, 0x6B, 0x2B, 0xEC, 0x98, 0x5D,
                                                         0x2C, 0x2D, 0xEC, 0x1D, 0x28, 0x33, 0x2C, 0x2D, 0x2A, 0x34, 0x2C, 0xAB, 0x2B, 0xCC, 0x98, 0x24, 0x2C, 0x2D, 0xAC, 0x37, 0x25, 0x27, 0x2C, 0x2F,
                                                         0x2A, 0xB0, 0x2C, 0xAB, 0x2B, 0xEC, 0x64, 0xA8, 0x2C, 0x2D, 0xAC, 0x2F, 0x27, 0x2B, 0x2C, 0x2F, 0xA8, 0x70, 0x2C, 0xAB, 0x0B, 0x0C, 0x64, 0xA8,
                                                         0x34, 0x2D, 0xAC, 0x33, 0xEF, 0x2B, 0xAC, 0x33, 0x6A, 0xEE, 0x2D, 0xAB, 0x1A, 0x0C, 0x44, 0xA8, 0x34, 0x2F, 0x2C, 0x33, 0x1F, 0x2B, 0xAE, 0x4B,
                                                         0x28, 0x0E, 0x2C, 0xAB, 0x2B, 0xD4, 0x44, 0xA8, 0x2C, 0xEF, 0xA8, 0x33, 0x25, 0x29, 0x2D, 0x33, 0x28, 0x0F, 0xAC, 0xA9, 0x2B, 0x0C, 0x48, 0xAA,
                                                         0x2C, 0xEF, 0x1A, 0x33, 0x25, 0x2B, 0x2C, 0x33, 0x10, 0x1C, 0x2D, 0x69, 0x2B, 0x0C, 0x60, 0x2A, 0x2C, 0x2F, 0xB2, 0x33, 0x25, 0x25, 0x2C, 0x33,
                                                         0x28, 0x1D, 0x22, 0xAB, 0x2B, 0x21, 0xA4, 0x28, 0x2C, 0x50, 0x2F, 0x33, 0x2B, 0x1D, 0xAC, 0x33, 0x29, 0x24, 0x3B, 0x2B, 0x2B, 0x2B, 0x24, 0xA8,
                                                         0x2C, 0x4C, 0x2F, 0x2F, 0x2B, 0x0F, 0x1C, 0x83, 0x25, 0x24, 0x6B, 0x2B, 0x2B, 0x2B, 0x26, 0x55, 0x2C, 0x2C, 0x5F, 0xAF, 0x2B, 0x28, 0x1C, 0x2B,
                                                         0x19, 0x0C, 0xAB, 0x2B, 0x2B, 0x2B, 0x2A, 0x3B, 0x2C, 0x2C, 0x63, 0xAD, 0x2B, 0x24, 0xA5, 0x2B, 0xA5, 0xAC, 0xAB, 0x2B, 0x2B, 0x2B, 0x2B, 0x3D,
                                                         0x2C, 0x44, 0x2D, 0xAC, 0x2B, 0x5C, 0x5F, 0x2B, 0x28, 0x38, 0x6B, 0x2B, 0x2B, 0x2B, 0x2B, 0x1C, 0x2C, 0x44, 0x2F, 0x2C, 0xAB, 0x0D, 0x93, 0x28,
                                                         0x24, 0x6A, 0x6B, 0x2B, 0x2B, 0x6B, 0x2B, 0x1C, 0x2C, 0x44, 0x2F, 0x2C, 0x2B, 0xB7, 0x1F, 0x2B, 0x24, 0x2A, 0x2F, 0x2B, 0x23, 0xAB, 0x2B, 0x1C,
                                                         0x30, 0x60, 0x33, 0x41, 0x28, 0x4B, 0x0F, 0x2B, 0xFB, 0x2B, 0x2F, 0x2B, 0x2B, 0x2B, 0x23, 0x1C, 0x32, 0xE2, 0x3B, 0xEB, 0x2B, 0x8B, 0x13, 0x2B,
                                                         0x2B, 0x2A, 0x3B, 0xAB, 0x2B, 0xEB, 0x2B, 0x1C, 0x33, 0x14, 0x37, 0x2B, 0x2B, 0x4B, 0x13, 0x2B, 0x2B, 0x24, 0x6B, 0xEB, 0x1F, 0x2A, 0x28, 0x1C,
                                                         0x2F, 0x26, 0x1D, 0x2B, 0x2B, 0xCB, 0xF3, 0x2B, 0xAB, 0x24, 0x2B, 0x2B, 0x27, 0x29, 0xA8, 0x1C, 0x2F, 0x28, 0x33, 0x1B, 0x2B, 0xF7, 0xBB, 0x2B,
                                                         0x2B, 0x23, 0x2B, 0x1B, 0x2B, 0x28, 0x2B, 0x1C, 0x6F, 0x2B, 0x0B, 0x2B, 0x2B, 0xF6, 0x6B, 0x2B, 0x2A, 0x3D, 0x2B, 0x2B, 0x2B, 0x2B, 0x2B, 0x1C,
                                                         0x75, 0xAB, 0x2B, 0x0B, 0x2B, 0x0C, 0xAB, 0x2B, 0x2A, 0x2D, 0xAB, 0x2B, 0x2B, 0x2B, 0xEB, 0xBC, 0x2D, 0x8B, 0x2B, 0x2B, 0x2B, 0x2B, 0xAB, 0x2B,
                                                         0x08, 0x2E, 0x6A, 0xAB, 0x2B, 0x13, 0x1B, 0x2C, 0x34, 0x5A, 0x2B, 0x27, 0x2B, 0x2B, 0x2B, 0x29, 0x28, 0x2D, 0x68, 0x04, 0x1B, 0x8A, 0xF1, 0x2C, 0x2C };
        //unsigned char recvData[0x241] = { 0x88, 0x90, 0x88, 0x88, 0x88, 0x88, 0x88, 0x08, 0x90, 0x88, 0x88, 0x88, 0x88, 0x8C, 0x88, 0x88, 0x88, 0x90, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0xA0, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x48, 0x88, 0x88, 0xB8, 0x8C, 0x88, 0x88, 0xA0, 0x88, 0x88, 0x98, 0x88, 0x88, 0x88, 0x88, 0xCF, 0x84, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x8F, 0x9E, 0x88, 0x88, 0x88, 0x88, 0x88, 0x90, 0xA8, 0xC8, 0x88, 0x98, 0x88, 0x8E, 0x88, 0x88, 0x97, 0x8F, 0x0C, 0x88, 0x88, 0x08, 0x88, 0x88, 0xB8, 0x88, 0x88, 0x88, 0x88, 0x90, 0x88, 0x88, 0x94, 0x89, 0x0D, 0x80, 0x98, 0x08, 0x88, 0x88, 0x88, 0x8E, 0x89, 0x80, 0x88, 0xA0, 0x88, 0x88, 0x94, 0x8B, 0x0F, 0x06, 0x89, 0x48, 0x88, 0x88, 0x88, 0x98, 0x07, 0x86, 0x88, 0xC4, 0x88, 0x88, 0x96, 0x89, 0x16, 0xC7, 0x8B, 0x48, 0x88, 0x88, 0x88, 0x88, 0xF9, 0x87, 0x08, 0x84, 0x88, 0x88, 0x97, 0x89, 0x26, 0x07, 0x15, 0x68, 0x88, 0x08, 0x88, 0x88, 0x58, 0x03, 0x68, 0x24, 0x88, 0x88, 0xC7, 0x8B, 0x47, 0x87, 0x68, 0xE8, 0x88, 0x88, 0xA8, 0xA8, 0x86, 0xA7, 0x78, 0x8F, 0x08, 0x88, 0x9F, 0x0F, 0xC7, 0x87, 0x78, 0xB8, 0x08, 0x88, 0x88, 0x99, 0x47, 0x17, 0x80, 0x8F, 0x88, 0x88, 0x8B, 0x5E, 0x07, 0x87, 0x80, 0xB8, 0x08, 0x8A, 0x88, 0x89, 0x87, 0x77, 0x84, 0x8E, 0x88, 0x88, 0xA7, 0x86, 0x07, 0x87, 0x84, 0xC0, 0x88, 0x89, 0x88, 0x8B, 0x07, 0x87, 0x84, 0x8F, 0x88, 0x90, 0xC4, 0x7A, 0x07, 0x87, 0x84, 0xA0, 0x88, 0x88, 0x88, 0x8B, 0xFF, 0x87, 0x86, 0x8B, 0x88, 0x90, 0x00, 0x78, 0x07, 0x87, 0x86, 0xA4, 0x88, 0x8A, 0xAA, 0x8F, 0x1F, 0x87, 0x86, 0x8B, 0x08, 0x88, 0x78, 0xC0, 0x07, 0x87, 0x06, 0x94, 0x88, 0x9F, 0xFB, 0x97, 0xAF, 0x87, 0x86, 0x89, 0x08, 0x88, 0x48, 0x9C, 0x07, 0x87, 0x86, 0x96, 0x88, 0xC7, 0x67, 0x32, 0xFB, 0x87, 0x86, 0x89, 0x1C, 0xC8, 0x54, 0x89, 0x07, 0x87, 0x86, 0x8E, 0xDC, 0xFB, 0x87, 0x7D, 0x01, 0x77, 0x86, 0x88, 0x86, 0x70, 0x6A, 0x2B, 0x87, 0x87, 0x86, 0x8E, 0x86, 0x87, 0x87, 0x87, 0x81, 0x87, 0x86, 0x88, 0x47, 0x84, 0x0F, 0x6B, 0x87, 0x87, 0x86, 0xDA, 0x87, 0x87, 0x87, 0x67, 0x81, 0x87, 0x84, 0x92, 0xC7, 0x86, 0x97, 0x7B, 0x87, 0x87, 0x84, 0x60, 0x87, 0x87, 0x87, 0x17, 0x68, 0x87, 0x84, 0xA7, 0x27, 0x87, 0x27, 0x4D, 0x87, 0x87, 0x85, 0x66, 0x07, 0x87, 0x87, 0x27, 0x79, 0x86, 0x80, 0xC7, 0x27, 0x57, 0x4F, 0x8F, 0x87, 0x87, 0x87, 0x86, 0xF3, 0x87, 0x87, 0xA7, 0x81, 0x80, 0x78, 0x07, 0x17, 0x57, 0x68, 0x97, 0x87, 0x87, 0x87, 0x87, 0x8B, 0x87, 0x87, 0xC5, 0x7B, 0x80, 0x74, 0x87, 0x4A, 0x87, 0x86, 0x07, 0x87, 0x87, 0x87, 0x86, 0xA7, 0x87, 0x87, 0x45, 0x7B, 0x78, 0x11, 0x87, 0x09, 0x87, 0x87, 0x87, 0x87, 0x87, 0x87, 0x84, 0x07, 0x87, 0x87, 0x67, 0x4D, 0x78, 0x8B, 0x87, 0x90, 0x87, 0x87, 0x87, 0x87, 0x87, 0x87, 0x81, 0x87, 0x87, 0x87, 0x57, 0x4F, 0x78, 0x8F, 0x86, 0xC0, 0x07, 0x87, 0x87, 0x87, 0x87, 0x47, 0x87, 0x87, 0x85, 0x87, 0x78, 0x97, 0x78, 0x8F, 0x85, 0x68, 0xA7, 0x87, 0x47, 0x87, 0x87, 0x87, 0x87, 0x87, 0x47, 0x87, 0x84, 0xA7, 0x78, 0x8F, 0x27, 0x08, 0xA3, 0x07, 0x87, 0x47, 0x87, 0x87, 0x87, 0x87, 0x87, 0x87, 0x87, 0x87, 0x78, 0x8F, 0xAC, 0x28, 0x97, 0x87, 0x87, 0x67, 0x87, 0x87, 0x87, 0x87, 0x85, 0x67, 0x84, 0x87, 0x78, 0x8A, 0x98, 0xAA, 0x8F, 0x87, 0x87, 0x07, 0x87, 0x37, 0x87, 0x87, 0x84, 0x10, 0x87, 0x87, 0x78, 0x88, 0xB8, 0x88, 0x8F, 0x67, 0x87, 0x03, 0x87, 0x27, 0x87, 0x87, 0x48, 0x50, 0x66, 0x87, 0x78, 0x88, 0xB8, 0x88, 0x8B, 0x07, 0x7F, 0x38, 0x82, 0xA7, 0x87, 0x87, 0x6C, 0x88, 0xE6, 0x87, 0x58, 0x90, 0x88, 0x88, 0x89, 0xC7, 0x2A, 0x28, 0x68, 0xA7, 0x6F, 0x31, 0x48, 0x88, 0x90, 0x47, 0x08, 0x88 };
        for (int i = 0; i < sizeof(recvData) + 1; i++)
        {
                byte (recvData[i])  -= byte( recvData[0x240]);               
        }
        int  dwJ = 0;
        byte arrymap[36][16] = { 0 };
        for (int i = 35; i >= 0;i--)
        {               
                for (int j = 0; j < 16; j++, dwJ++)
                {
                        arrymap[i][j] = byte(recvData[dwJ]);
                }
        }

        //创建位图文件头
        BITMAPFILEHEADER aheaer;
        aheaer.bfType = 0x4d42;
        aheaer.bfSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + 0x8 + 0x240/* sizeof(arrymap)*/;
        aheaer.bfReserved1 = 0;
        aheaer.bfReserved2 = 0;
        aheaer.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + 0x8;

        BITMAPINFOHEADER aInfo;
        aInfo.biSize = 0x28;
        aInfo.biWidth = 128;
        aInfo.biHeight = 36;
        aInfo.biPlanes = 1;
        aInfo.biBitCount = 1/*8*/;
        aInfo.biCompression = 0;
        aInfo.biSizeImage = 0;
        aInfo.biXPelsPerMeter = 0;
        aInfo.biYPelsPerMeter = 0;
        aInfo.biClrUsed = 2;
        aInfo.biClrImportant = 2;

        unsigned char aRound[0x8] = { 0 };
        aRound[4] = 0xff;
        aRound[5] = 0xff;
        aRound[6] = 0xff;
        aRound[7] = 0xff;


        //如果这样能正常显示 但是我不想写入到文件就显示图片
        /*HANDLE fh = CreateFileA("6.bmp", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
                FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL);

        DWORD dwWritten = 0;
        if (fh == INVALID_HANDLE_VALUE)return FALSE;

        WriteFile(fh, (LPSTR)&aheaer, sizeof(BITMAPFILEHEADER), &dwWritten, NULL);
        WriteFile(fh, (LPSTR)&aInfo, sizeof(BITMAPINFOHEADER), &dwWritten, NULL);
        WriteFile(fh, (LPSTR)aRound, 0x8, &dwWritten, NULL);
        WriteFile(fh, (LPSTR)arrymap, sizeof(arrymap), &dwWritten, NULL);

        CloseHandle(fh);*/
        CImage mImg;
        mImg.Load(_T("F:\\VC++练习示例\\MFC\\TLClinet\\TLClinet\\6.bmp"));  //【请问这怎么写呢】
        CDC *pShowDC = CDC::FromHandle(::GetDC(GetDlgItem(IDC_S_Pic)->m_hWnd));
        //pShowDC->FillRect(showRect, CBrush::FromHandle(::CreateSolidBrush(GetSysColor(COLOR_3DFACE))));
        mImg.StretchBlt(pShowDC->m_hDC, 0, 0,128, 36, SRCCOPY);
        ::ReleaseDC(GetDlgItem(IDC_S_Pic)->m_hWnd, pShowDC->m_hDC);


         return TRUE;

       
}




上一篇:静态数据成员和静态成员函数
下一篇:映射模式对TextOut的影响
11_avatar_middle
ico_lz  楼主| 发表于 2016-8-13 18:07:10 | 显示全部楼层
还不没有人回复?  真是晕了..
04_avatar_middle
online_vip 发表于 2016-8-14 16:42:03 | 显示全部楼层
有个API叫StretchDIBits
您需要登录后才可以回帖 登录 | 加入驿站 qq_login

本版积分规则

关闭

站长提醒上一条 /2 下一条

QQ|小黑屋|手机版|VC驿站 ( 辽ICP备09019393号tongdun|网站地图wx_jqr

GMT+8, 2019-7-18 09:31

Powered by Discuz! X3.4

© 2009-2019 cctry.com

快速回复 返回顶部 返回列表