CreateDIBSection failed

偶尔善良 提交于 2019-12-11 02:15:57

问题


BITMAPINFO bmi;
memset(&bmi,0,sizeof(BITMAPINFO));
bmi.bmiHeader.biSize            = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth           =m_pImg->GetWidth();
bmi.bmiHeader.biHeight          =m_pImg->GetHeight();
bmi.bmiHeader.biPlanes          = 1;
//if(   m_pImg->GetInfo()->biBitCount!=16)  
//{
//  bmi.bmiHeader.biBitCount    =   m_pImg->GetInfo()->biBitCount;
//}
//else 
//{
//ASSERT((m_pImg->GetInfo())->bmiHeader->biBitCount == 24);
bmi.bmiHeader.biBitCount=24;
bmi.bmiHeader.biCompression     = BI_RGB;
if (bmi.bmiHeader.biSizeImage == 0)
    bmi.bmiHeader.biSizeImage =
    WidthBytes(bmi.bmiHeader.biWidth,bmi.bmiHeader.biBitCount) * bmi.bmiHeader.biHeight;
if(bmi.bmiHeader.biClrUsed == 0 && bmi.bmiHeader.biBitCount <16)
    bmi.bmiHeader.biClrUsed=DWORD(1 <<bmi.bmiHeader.biBitCount);
m_nNewSize=bmi.bmiHeader.biSizeImage;

if(m_hbmCanvasBitmap!=NULL)
{
    DeleteObject(m_hbmCanvasBitmap);
    m_hbmCanvasBitmap=NULL;
    m_pCanvasBits=NULL;
}
//  创建直接与DC相关联的位图
m_hbmCanvasBitmap=CreateDIBSection(m_hDC, &bmi, DIB_RGB_COLORS,(void**)&m_pCanvasBits, NULL, NULL); 

// after CreateDIBSection I found the error code is 8, no enough resource.

How can I avoid this error? I pass width: 3500 height 2500 many thanks!


回答1:


I think the answer to this is the same as the answer to your earlier question: your bitmaps are way too big.

Also, since your dimensions are now half the dimensions of the bitmap in your earlier question, I'm guessing you're trying to break the destination up into quadrants, but now you don't have enough resources to even create the destination bitmap. This may mean that you're also not releasing the bitmap memory from your previous attempts. You may want to reboot and try all this again with much smaller destination images.




回答2:


There simply isn't enough memory to complete your command. You can't "fix" it as is, except to try and break some memory boundary.

Rather, you need to split whatever image your working on into manageable sizes, so they can be swapped in and out.



来源:https://stackoverflow.com/questions/1442213/createdibsection-failed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!