win32如何从内存加载位图? 本帖最后由 weiwuyuan 于 2011-10-23 16:12:33 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 很简单,我现在有一个RGB数据,比如:int bmp[4*4] ={ 0xff00ff, 0xff01ff, 0xff02ff, 0xff03ff, 0xff00ff, 0xff01ff, 0xff02ff, 0xff03ff, 0xff00ff, 0xff01ff, 0xff02ff, 0xff03ff, 0xff00ff, 0xff01ff, 0xff02ff, 0xff03ff,};我想把这个RGB数据填充进位图中,怎么填充?就是要实现,不从文件加载,从内存加载 你是想直接在内存中将位图解码吗? 如果是的话,可以尝试用CXimage这个类库,很强大的 http://baike.baidu.com/view/189487.htm 其实只要十几行代码就OK了:// 绘制自定义位图像素 { // 获取tga像素 BYTE* pBmpData = NULL; int bmpWidth = 0; int bmpHeight = 0; GetBmpFromTga("test.tga", &pBmpData, &bmpWidth, &bmpHeight, NULL); UINT* pBmp32 = (UINT*)pBmpData; const int BMP_WIDTH = bmpWidth; const int BMP_HEIGHT = bmpHeight; HBITMAP hCustomBmp = CreateCompatibleBitmap(hdc, BMP_WIDTH, BMP_HEIGHT); UINT* pData = new UINT[BMP_WIDTH*BMP_HEIGHT]; BITMAPINFO bmpInfo; bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bmpInfo.bmiHeader.biWidth = BMP_WIDTH; bmpInfo.bmiHeader.biHeight = BMP_HEIGHT; bmpInfo.bmiHeader.biPlanes = 1; bmpInfo.bmiHeader.biCompression = BI_RGB; bmpInfo.bmiHeader.biBitCount = 32; GetDIBits(hdc, hCustomBmp, 0, BMP_HEIGHT, pData, &bmpInfo, DIB_RGB_COLORS); for (int i=0; i<BMP_WIDTH*BMP_HEIGHT; i++) { pData[i] = (*pBmp32) & 0x00ffffff; pBmp32++; } SetDIBits(hdc, hCustomBmp, 0, BMP_HEIGHT, pData,&bmpInfo, DIB_RGB_COLORS); HDC hh = CreateCompatibleDC(NULL); SelectObject(hh, hCustomBmp); BitBlt(hdc, 0, 0, BMP_WIDTH, BMP_HEIGHT, hh, 0, 0, SRCCOPY); } 程序有时候崩溃?请大家帮帮忙 请问如何在MSDN网站中找到一个win32 api 的详细说明,比如PeekMessage? 程序界面如何实现多语言版本 请问 如何发送电子邮件? 基于对话框的mfc,如何把一个字符串显示到子对话框的控件中 Shortcut在MFC中怎么实现? 哪里能够找得到powerpoint控件?100分立即送上 求助,头疼的问题 help!!!!!!!!!!!!! 我用MFC的框架做的ActiveX控件,需要在控件中读出系统当前的时间,怎么实现? 文件映射内存图像细化(急) udp广播,数据分包和重组
很简单,我现在有一个RGB数据,比如:
int bmp[4*4] =
{
0xff00ff, 0xff01ff, 0xff02ff, 0xff03ff,
0xff00ff, 0xff01ff, 0xff02ff, 0xff03ff,
0xff00ff, 0xff01ff, 0xff02ff, 0xff03ff,
0xff00ff, 0xff01ff, 0xff02ff, 0xff03ff,
};我想把这个RGB数据填充进位图中,怎么填充?
就是要实现,不从文件加载,从内存加载
{
// 获取tga像素
BYTE* pBmpData = NULL;
int bmpWidth = 0;
int bmpHeight = 0; GetBmpFromTga("test.tga", &pBmpData, &bmpWidth, &bmpHeight, NULL);
UINT* pBmp32 = (UINT*)pBmpData; const int BMP_WIDTH = bmpWidth;
const int BMP_HEIGHT = bmpHeight; HBITMAP hCustomBmp = CreateCompatibleBitmap(hdc, BMP_WIDTH, BMP_HEIGHT); UINT* pData = new UINT[BMP_WIDTH*BMP_HEIGHT];
BITMAPINFO bmpInfo;
bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmpInfo.bmiHeader.biWidth = BMP_WIDTH;
bmpInfo.bmiHeader.biHeight = BMP_HEIGHT;
bmpInfo.bmiHeader.biPlanes = 1;
bmpInfo.bmiHeader.biCompression = BI_RGB;
bmpInfo.bmiHeader.biBitCount = 32; GetDIBits(hdc, hCustomBmp, 0, BMP_HEIGHT, pData, &bmpInfo, DIB_RGB_COLORS); for (int i=0; i<BMP_WIDTH*BMP_HEIGHT; i++)
{
pData[i] = (*pBmp32) & 0x00ffffff;
pBmp32++;
} SetDIBits(hdc, hCustomBmp, 0, BMP_HEIGHT, pData,&bmpInfo, DIB_RGB_COLORS); HDC hh = CreateCompatibleDC(NULL);
SelectObject(hh, hCustomBmp);
BitBlt(hdc, 0, 0, BMP_WIDTH, BMP_HEIGHT, hh, 0, 0, SRCCOPY);
}