如何将位图文件写入内存,然后在将其在指定位置显示出来。 如题!是用SetDIBitsToDevice函数吗?函数的返回结果是正确的,为什么显示不出来图像呢? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 loadimage读入内存,用SetDIBitsToDevice或bitblt显示 void CFile2MemoView::OnDraw(CDC* pDC){ CFile2MemoDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); // TODO: add draw code for native data here BYTE *File2MemoBmpBuf = new BYTE [512*512*3]; CRect clientRect; CBitmap bitmap; CClientDC dc(this); CDC memDC; DWORD i=0,dwCount=0; int x=0,y=0; COLORREF color; CRect prevrect(0,0,512,512); this->GetClientRect(&clientRect); bitmap.CreateCompatibleBitmap(&dc,512,512); memDC.CreateCompatibleDC(&dc); memDC.SelectObject(&bitmap); memDC.SetMapMode(MM_TEXT); double dScale=1.0*clientRect.Width()/512; dwCount=512*512*3; if(File2MemoBmpBuf != NULL) delete File2MemoBmpBuf; File2MemoBmpBuf=new BYTE[dwCount]; i=0; for(y=512 - 1;y>=0;y--) { for(x=0;x<512;x++) { i=(512-1-y)*512+x; //color=memDC.GetPixel(x,y); color=int(i%256); File2MemoBmpBuf[i*3]=(BYTE)((color&0x00ff0000)>>16); File2MemoBmpBuf[i*3+1]=(BYTE)((color&0x0000ff00)>>8); File2MemoBmpBuf[i*3+2]=(BYTE)((color&0x000000ff)); } } memDC.SetMapMode(MM_LOENGLISH); //显示图像 //HDC hDC; BITMAPINFO bmInfo; bmInfo.bmiHeader.biSize=sizeof(bmInfo.bmiHeader); bmInfo.bmiHeader.biWidth=512; bmInfo.bmiHeader.biHeight=512; bmInfo.bmiHeader.biPlanes=1; bmInfo.bmiHeader.biBitCount=24; bmInfo.bmiHeader.biCompression=BI_RGB; bmInfo.bmiHeader.biSizeImage=512*512*3; bmInfo.bmiHeader.biClrUsed=1; bmInfo.bmiHeader.biClrImportant=0; BOOL flag; int iRet; iRet=SetDIBitsToDevice(memDC,0,0,512,512,0,0,0,512,File2MemoBmpBuf,&bmInfo,DIB_RGB_COLORS); if (iRet == 0) flag=false;这是我的源代码,请问为什么显示不出来? 没有将图画在DC上!dc.BitBlt(&memDC); 【gloomyfish】看了一下自己2006以前发的帖子,感觉问题好弱智 CListCtrl能实现设置单行高度吗? vc+sql+ado日期写入数据库总是出问题 编译通过,链接时报错,为何?错误是,,, 【200分求助】基于UDP协议的可靠的电子邮件传输系统! 请教vc中一些简单的问题 高手支招 在IE中调试组件不用机器重启 简单。到微软哪里去查Q196342这样的问题代号 骂了老半天,现在改好了该表扬一下了,祝愿CSDN越办越好 ***用vc实现xml的树式表达!欢迎大家讨论,分不够可以再加!*** 请大家帮我想想这是为什么? 菜鸟问题:如何去掉工具栏上自己不想要的按钮?
{
CFile2MemoDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
BYTE *File2MemoBmpBuf = new BYTE [512*512*3]; CRect clientRect;
CBitmap bitmap;
CClientDC dc(this);
CDC memDC;
DWORD i=0,dwCount=0;
int x=0,y=0;
COLORREF color;
CRect prevrect(0,0,512,512);
this->GetClientRect(&clientRect);
bitmap.CreateCompatibleBitmap(&dc,512,512);
memDC.CreateCompatibleDC(&dc);
memDC.SelectObject(&bitmap); memDC.SetMapMode(MM_TEXT);
double dScale=1.0*clientRect.Width()/512;
dwCount=512*512*3;
if(File2MemoBmpBuf != NULL)
delete File2MemoBmpBuf;
File2MemoBmpBuf=new BYTE[dwCount];
i=0; for(y=512 - 1;y>=0;y--)
{
for(x=0;x<512;x++)
{
i=(512-1-y)*512+x;
//color=memDC.GetPixel(x,y);
color=int(i%256);
File2MemoBmpBuf[i*3]=(BYTE)((color&0x00ff0000)>>16);
File2MemoBmpBuf[i*3+1]=(BYTE)((color&0x0000ff00)>>8);
File2MemoBmpBuf[i*3+2]=(BYTE)((color&0x000000ff));
}
}
memDC.SetMapMode(MM_LOENGLISH);
//显示图像
//HDC hDC;
BITMAPINFO bmInfo;
bmInfo.bmiHeader.biSize=sizeof(bmInfo.bmiHeader);
bmInfo.bmiHeader.biWidth=512;
bmInfo.bmiHeader.biHeight=512;
bmInfo.bmiHeader.biPlanes=1;
bmInfo.bmiHeader.biBitCount=24;
bmInfo.bmiHeader.biCompression=BI_RGB;
bmInfo.bmiHeader.biSizeImage=512*512*3;
bmInfo.bmiHeader.biClrUsed=1;
bmInfo.bmiHeader.biClrImportant=0; BOOL flag;
int iRet;
iRet=SetDIBitsToDevice(memDC,0,0,512,512,0,0,0,512,File2MemoBmpBuf,&bmInfo,DIB_RGB_COLORS);
if (iRet == 0)
flag=false;这是我的源代码,请问为什么显示不出来?
dc.BitBlt(&memDC);