HDC hdc;
HWND hwnd = GetSafeHwnd();
hdc = ::GetDC(hwnd);
BITMAPINFO *m_pBMI = new BITMAPINFO;//彩色图像信息头
m_pBMI->bmiHeader.biBitCount = 32;//颜色深度
m_pBMI->bmiHeader.biClrImportant = 0;
m_pBMI->bmiHeader.biClrUsed = 0;
m_pBMI->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
m_pBMI->bmiHeader.biWidth = info[0].Width;
m_pBMI->bmiHeader.biHeight = -(info[0].Heigth);
m_pBMI->bmiHeader.biPlanes = 1;
m_pBMI->bmiHeader.biCompression = BI_RGB;//不压缩
m_pBMI->bmiHeader.biSizeImage = info[0].Length;
m_pBMI->bmiHeader.biXPelsPerMeter =0;
m_pBMI->bmiHeader.biYPelsPerMeter =0;
//以上填充结构体都其实不重要..不是问题所在...
StretchDIBits(hdc,0,0,info[0].Width,info[0].Heigth,0,0,
info[0].Width,info[0].Heigth,ptr[0],m_pBMI,DIB_RGB_COLORS,SRCCOPY);
::ReleaseDC(m_hWnd,hdc);显示的代码就这么点,在基于对话框的程序中能正常显示,但在单文档程序中的VIEW类中的客户区却显示不出来,但是我试了可以在其中划线.....求高手指点!

解决方案 »

  1.   

    这段代码是在哪个函数中?把这个函数中的代码贴全。另外info[0]是从哪来的?调试看看info[0]中的值是否正确。
      

  2.   

    void CMy4CaptureView::OnSigCapture() 
    {
    // TODO: Add your command handler code here
    MV_IMAGEINFO info;
    unsigned char FileName[256];
    PVOID ptr;
    DWORD Num = MV_GetDeviceNumber();     MV_SetDeviceParameter(hDvcHdl[0],SET_GARBIMAGEINFO, (DWORD)&info );// 得到当前的图像的信息
    ptr = MV_CaptureSingle(hDvcHdl[0], FALSE, NULL,0, &info);//采集一幅图像,返回RGB内存指针 HDC hdc;
    HWND hwnd = GetSafeHwnd();
    hdc = ::GetDC(hwnd);
    BITMAPINFO *m_pBMI = new BITMAPINFO;//彩色图像信息头
    m_pBMI->bmiHeader.biBitCount = 32;//颜色深度
    m_pBMI->bmiHeader.biClrImportant = 0;
    m_pBMI->bmiHeader.biClrUsed = 0;
    m_pBMI->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    m_pBMI->bmiHeader.biWidth = info.Width;
    m_pBMI->bmiHeader.biHeight = -(info.Heigth);
    m_pBMI->bmiHeader.biPlanes = 1;
    m_pBMI->bmiHeader.biCompression = BI_RGB;//不压缩
    m_pBMI->bmiHeader.biSizeImage = info.Length;
    m_pBMI->bmiHeader.biXPelsPerMeter =0;
    m_pBMI->bmiHeader.biYPelsPerMeter =0;

    StretchDIBits(hdc,0,0,768,576,0,0,
    768,576,ptr,m_pBMI,DIB_RGB_COLORS,SRCCOPY);
    ::ReleaseDC(m_hWnd,hdc);
                    //以下为存图为BMP文件,可以正常将采集的图存储
    CString filename,directory;
    filename.Format("\\Card%d_%d",1, FileNUM);
    directory=m_edit1;
    directory+=filename;
    strcpy((char*)&FileName[0],directory);
    MV_SaveFile( FileName, BMP, ptr, &info, 1, FALSE, FALSE, 0 );  //将图片存位BMP格式
    //AfxMessageBox("已采集单帧图像");}
      

  3.   

    我查看了  是StretchDIBits错误 返回值是0
    但是我不知道为什么会错.
      

  4.   

    m_pBMI->bmiHeader.biHeight = -(info[0].Heigth); 这里的高度是个负数