none
在视图类的OnDraw函数使用StretchBlt绘图无显示 RRS feed

  • 问题

  •        代码大致如下:

    BITMAPINFO bi;
    bi.bmiHeader.biSize == sizeof(BITMAPINFOHEADER);
    bi.bmiHeader.biHeight = iRows;
    bi.bmiHeader.biWidth = iCols;
    bi.bmiHeader.biPlanes = 1;
    bi.bmiHeader.biBitCount = 24;
    bi.bmiHeader.biCompression = BI_RGB;
    HBITMAP hbmp;
    hbmp = ::CreateDIBitmap(pDC->m_hDC, &bi.bmiHeader, CBM_INIT, pix, &bi, DIB_RGB_COLORS);
    CDC src_dc;
    src_dc.CreateCompatibleDC(pDC);src_dc.SelectObject(hbmp);
    dcMem.StretchBlt(desx, desy, desw, desh, &src_dc, srcx, srcy, srcw, srch, SRCCOPY);

          使用dcMem.FillSolidRect(&rc,255)是有显示的,请教一下各位大神,谢谢了!

    2021年3月10日 9:02

全部回复

  • CDC dcMem;
    dcMem.CreateCompatibleDC(pDC);
    CBitmap bmp, *pOldBmp;
    bmp.CreateCompatibleBitmap(pDC, rc.Width(), rc.Height());
    pOldBmp = (CBitmap*)dcMem.SelectObject(&bmp);
    dcMem.FillSolidRect(&rc, RGB(0, 0, 0));

    补充一下前面的代码,我用的是win10,vs2015

    2021年3月10日 9:06
  • 不知道为什么CreateDIBitmap总是返回空
    2021年3月11日 8:02
  • 你好,

    感谢您在MSDN中文论坛发帖提问。

    >>在视图类的OnDraw函数使用StretchBlt绘图无显示

    请你提供完整的代码小样,让我们重现你的问题。iRows iCols是什么?pix是什么?以及desx, desy, desw, desh和srcx, srcy, srcw, srch代表的坐标值又是什么?

    我建议你可以参考这个例子:https://docs.microsoft.com/en-us/windows/win32/gdi/scaling-an-image

    Best Regards,

    Jeanine Zhang


    "Visual c++" forum will be migrating to a new home on Microsoft Q&A !
    We invite you to post new questions in the "Developing Universal Windows apps" forum’s new home on Microsoft Q&A !
    For more information, please refer to the sticky post.

    2021年3月11日 8:03
    版主
  • 你好,

    >>不知道为什么CreateDIBitmap总是返回空

    根据这篇文档:CreateDIBitmap函数(wingdi.h)

    CBM_INIT:如果设置了该标志,那么系统将使用lpblnit和lpbmi两个参数指向的数据来对位图中的位进行初始化。

    lpblnit:该指针指向包含初始的位图数据的字节类型数组。数据格式与参数lpbmi指向的BITMAPINFO结构中的成员biBitCount有关。

    请问你这里使用的pix是什么?

    Best Regards,

    Jeanine Zhang


    "Visual c++" forum will be migrating to a new home on Microsoft Q&A !
    We invite you to post new questions in the "Developing Universal Windows apps" forum’s new home on Microsoft Q&A !
    For more information, please refer to the sticky post.



    2021年3月12日 2:05
    版主