1

Added a picture control to my MFC dialog. Set its type to Frame. Need to display 8 bit buffer (NOT LOADED From file) on the picture control. The image is scaled down, repeated , tilted diagonally. Not correct. I could not make it fit the control properly. resized the control but still the same problem.

w = 750;
h = 850;
bpp = 8

void CDispDlg::BuildINfoAndDisp(int w, int h)
{
    m_pbmi = (BITMAPINFO*) new BYTE[sizeof(BITMAPINFO) + 256) * sizeof(RGBQUAD)];
    m_pbmi->bmiHeader.bSize=sizeof(BITMAPINFOHEADER);
    m_pbmi->bmiHeader.biPlanes = 1;
    m_pbmi->bmiHeader.biBitCount = bpp;
    m_pbmi->bmiHeader.biCompression = BI_RGB;
    m_pbmi->bmiHeader.biSizeImage = 0;
    m_pbmi->bmiHeader.biXpelsPerMeter = 0;
    m_pbmi->bmiHeader.biYpelsPerMeter = 0;
    m_pbmi->bmiHeader.biClrUsed = 0;
    m_pbmi->bmiHeader.biClrImportant = 0;
    
    for (int i = 0; i< 256; i++)
    {
        m_pbmi->bmiColors[i].rgbBlue = i;
        m_pbmi->bmiColors[i].rgbGreen = i;
        m_pbmi->bmiColors[i].rgbBRed = i;
        m_pbmi->bmiColors[i].rgbReserved = 0;
        
    }
    
    m_pbmi->bmiHeader.biWidth = w;
    m_pbmi->bmiHeader.biHeight = -h;
    
    CClientDC dc(GetDlgItem(IDC_PicCntrl_DSIP));
    
    CRect rect;
    GetDlgItem(IDC_PicCntrl_DSIP)->GetClientRect(&rect);
    
    SetStrechBltMode(dc.GetSafeHdc(), COLORNOCOLOR);
    StretchBIBits(dc.GetSafeHdc(), 0 ,0 , rect.Width, rect.Height, 0,0, m_wImage, m_hImage, &m_U8imageBuf, m_pbmi,DIB_RGB_COLORS, SRCCOPY);
}
IInspectable
  • 46,945
  • 8
  • 85
  • 181
umc
  • 39
  • 3
  • I can't quite figure out how many typos there are in this expression: `new BYTE(sizeof(BITMAPINFO) + 256) * sizeof(RGBQUAD)];`. – Adrian Mole Aug 31 '20 at 06:11
  • *"the same problem"* - What *is* the problem? – IInspectable Aug 31 '20 at 08:58
  • corrected a typo. Had to type it in. why the image shows up diagonally?. – umc Aug 31 '20 at 14:13
  • 4
    Scanlines need to be `DWORD`-aligned. If they aren't, the rendered image may appear skewed. 750 isn't an even multiple of 4. It would help if you provided an image of the result. – IInspectable Aug 31 '20 at 19:04
  • made it work by mapping the 8 bit image buffer to 24 bit image buffer. Will check into the scan lines. Is there any way to get image X and Y by getting the point coordinate on the picture control?. – umc Sep 01 '20 at 06:07

0 Answers0