如题!
是用SetDIBitsToDevice函数吗?函数的返回结果是正确的,为什么显示不出来图像呢?

解决方案 »

  1.   

    loadimage读入内存,用SetDIBitsToDevice或bitblt显示
      

  2.   

    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;这是我的源代码,请问为什么显示不出来?
      

  3.   

    没有将图画在DC上!
    dc.BitBlt(&memDC);