现在我有图片的数据
BYTE *pbyImage;//保存jpg图片的二进制数据;
int  nImagelen;//保存当前jpg图片的长度;
以前一直用的别人给的控件显示, 现在我想用现成的
控件显示,如picture 或 satic控件显示图片.
现在我有这个图片的数据和长度怎么用控件显示?
//picture控件变量
CStatic m_Pic;

解决方案 »

  1.   

    自己从CStatic派生一类,响应WM_PAINT消息,用SetDIBitsToDevice显示。
      

  2.   

    看错了,jpg不能这样显示,GDI+好象可以,我不太熟。
      

  3.   

    http://topic.csdn.net/t/20050113/08/3721278.html
      

  4.   

    thanks!
    这个是用图片路径显示,我的需求是用图片数据显示,不一样啊..
      

  5.   

    解码后,可以创建内存dc,再CreateDIBSection,然后把图片数据拷贝到内存dc,最后bitblt到控件DC
      

  6.   

    Load的时候失败. 请大家帮忙排查一下是哪里有问题..找了一上午都没找到
    void CExportImageDlg::OnLvnItemchangedListDatabase(NMHDR *pNMHDR, LRESULT *pResult)
    {
    LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
    // TODO: 在此添加控件通知处理程序代码
    int nSel = pNMLV->iItem;
    if (nSel < 0)
    return;
    BYTE *pbyImage = (BYTE*)m_DataList.GetItemData(nSel);

    if (pbyImage)
    {
    int  nImagelen = *(UINT*)pbyImage;
    pbyImage += sizeof(UINT); HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE,nImagelen);
    if (hGlobal == NULL)
    {
    AfxMessageBox(L"GlobalAlloc error");
    return;
    }
    BYTE *pbyData = (BYTE*)GlobalLock(hGlobal);
    memcpy(pbyData, &pbyImage, nImagelen);
    GlobalUnlock(hGlobal); LPSTREAM pstm = NULL;
    HRESULT hr = CreateStreamOnHGlobal(hGlobal, TRUE, &pstm);
    if (hr != S_OK)
    {
    AfxMessageBox(L"CreateStreamOnHGlobal error");
    return;
    }
    CImage Image;
    HRESULT hLoad = Image.Load(pstm);
    if ( hLoad != S_OK)
    { //GetLastError();获得的是 0
    DWORD dwError = GetLastError();
    CString strErrMsg;
    strErrMsg.Format(_T("Load Error ,the error code is %d"), dwError); AfxMessageBox(strErrMsg);
    return;
    }
    CRect rect;
    m_Pic.GetWindowRect(&rect);
    HDC hdc = ::GetDC(m_Pic.m_hWnd);
    if (hdc)
    {
    Image.Draw(hdc, 0, 0);
    }
    } *pResult = 0;
    }
      

  7.   

    还是得靠自己...搞定
    void CExportImageDlg::OnLvnItemchangedListDatabase(NMHDR *pNMHDR, LRESULT *pResult)
    {
    LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
    // TODO: 在此添加控件通知处理程序代码
    int nSel = pNMLV->iItem;
    if (nSel < 0)
    return;
    BYTE *pbyImage = (BYTE*)m_DataList.GetItemData(nSel);

    if (pbyImage)
    {
    int  nImagelen = *(UINT*)pbyImage;
    pbyImage += sizeof(UINT); HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE,nImagelen);
    if (hGlobal == NULL)
    {
    AfxMessageBox(L"GlobalAlloc error");
    return;
    }
    BYTE *pbyData = (BYTE*)GlobalLock(hGlobal);
    memcpy(pbyData, pbyImage, nImagelen);
    GlobalUnlock(hGlobal); LPSTREAM pstm = NULL;
    HRESULT hr = CreateStreamOnHGlobal(hGlobal, TRUE, &pstm);
    if (hr != S_OK)
    {
    AfxMessageBox(L"CreateStreamOnHGlobal error");
    return;
    }
    CImage Image;
    Image.Destroy(); HRESULT hLoad = Image.Load(pstm);
    if ( hLoad != S_OK)
    {
    DWORD dwError = GetLastError();
    CString strErrMsg;
    strErrMsg.Format(_T("Load Error ,the error code is %d"), dwError);
    AfxMessageBox(strErrMsg);
    return;
    }
    CRect rect;
    m_Pic.GetWindowRect(&rect);
    HDC hdc = ::GetDC(m_Pic.m_hWnd);
    if (hdc)
    {
    Image.Draw(hdc, 0, 0, rect.Width(),rect.Height());
    m_Pic.Invalidate();
    }
    }

    *pResult = 0;
    }