CDC memDC;
memDC.CreateCompatibleDC(pDC); HBITMAP hBitmap;
hBitmap=(HBITMAP)::LoadImage(NULL,"e:\2.jpg",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
bitmap.Attach(hBitmap);
bitmap.CreateCompatibleBitmap(pDC,rc.Width(),rc.Height()); memDC.SelectObject(&bitmap);
memDC.FillSolidRect(0,0,rc.Width(),rc.Height(),RGB(255,255,255));        pDC->BitBlt(
rc.left,rc.top,
Rect.Width(),
Rect.Height(),
&memDC,
0,0,
SRCCOPY);我用上诉代码想将e:\2.jpg的图片读入内存,然后再显示。
但结果是只显示一个和图片大小一样的一块白色。应该是文件读取有问题吧?
请教应该怎么写

解决方案 »

  1.   

    我读取bmp文件也还是一样,显示出来的是图片大小的一块白。
      

  2.   

    memDC.FillSolidRect(0,0,rc.Width(),rc.Height(),RGB(255,255,255));
    你这句就把白色背景选进去了,当然现实白色了
      

  3.   

    Res
    This function returns the previously selected object of the specified type. An application should always replace a new object with the original, default object after it has finished drawing with the new object.  CDC MemDC;
    CBitmap MemBitmap;
    MemDC.CreateCompatibleDC(pDC);
    MemBitmap.CreateCompatibleBitmap(pDC,drawRect.Width(),drawRect.Height());
    CBitmap* pOldBitmap=MemDC.SelectObject(&MemBitmap);
    MemDC.FillSolidRect(drawRect,RGB(0,0,0)); pDC->BitBlt(0,0,drawRect.Width(),drawRect.Height(),&MemDC,0,0,SRCCOPY); MemDC.SelectObject(pOldBitmap); MemBitmap.DeleteObject();
    MemDC.DeleteDC();