as title

解决方案 »

  1.   

    这里有一个例子:
    在VC下显示JPEG、GIF格式图像的一种简便方法
    http://www.ccw.com.cn/htm/app/aprog/01_7_27_2.asp
      

  2.   

    去找个库把jpg转化成bmp,然后显示bmp就行了
      

  3.   

    IStream *pStm; 
    CFileStatus fstatus; 
    CFile file; 
    LONG cb; 
    CRect r_Show;
    HDC hdc;

    m_Show.GetClientRect(r_Show);
    int xpos=r_Show.left;
    int ypos=r_Show.top;
    int Widthpos=r_Show.Width();
    int heightpos=r_Show.Height(); 
    if (file.Open(m_PhotoPath,CFile::modeRead)&&file.GetStatus(m_PhotoPath,fstatus)&& ((cb = fstatus.m_size) != -1)) 

    HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, cb); 
    LPVOID pvData = NULL; 
    if (hGlobal != NULL) 

    if ((pvData = GlobalLock(hGlobal)) != NULL) 

    file.ReadHuge(pvData, cb); 
    GlobalUnlock(hGlobal); 
    CreateStreamOnHGlobal(hGlobal, TRUE, &pStm);  if(SUCCEEDED(OleLoadPicture(pStm,fstatus.m_size,TRUE,IID_IPicture,(LPVOID*)&pPic))) 

    OLE_XSIZE_HIMETRIC hmWidth; 
    OLE_YSIZE_HIMETRIC hmHeight;  pPic->get_Width(&hmWidth); 
    pPic->get_Height(&hmHeight); 
    // double fX,fY; 
    // fX = (double)pDC->GetDeviceCaps(HORZRES)*(double)hmWidth/((double)pDC->GetDeviceCaps(HORZSIZE)*100.0); 
    // fY = (double)pDC->GetDeviceCaps(VERTRES)*(double)hmHeight/((double)pDC->GetDeviceCaps(VERTSIZE)*100.0); 
    // if(FAILED(pPic->Render(*pDC,0,0,(DWORD)fX,(DWORD)fY,0,hmHeight,hmWidth,-hmHeight,NULL))) 
    double fX,fY; 
    fX = r_Show.Width();
    fY = r_Show.Height();
    hdc=::GetDC(m_Show.m_hWnd); 
    if(FAILED(pPic->Render(hdc,xpos,ypos,(DWORD)fX,(DWORD)fY,0,hmHeight,hmWidth,-hmHeight,NULL))) 
    AfxMessageBox("Failed To Render The picture!"); 
    // pPic->Release(); 

    else 
    AfxMessageBox("Error Loading Picture From Stream!"); 
    }


    GlobalFree(hGlobal);

    else 
    AfxMessageBox("Can't Open Image File!");
      

  4.   

    还是转成bmp吧,大家都是这么干的做完了自己也可以写控件了 ^_^
      

  5.   

    #define HIMETRIC_INCH 2540
    LPPICTURE gpPicture;//必须是全局定义的.
    ShowPicture(CDC* pDC,CString m_strBRoute,int x,int y,int width,int height)
    {
    HANDLE hFile = CreateFile(m_strBRoute, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
    _ASSERTE(INVALID_HANDLE_VALUE != hFile); // 取得文件大小
    DWORD dwFileSize = GetFileSize(hFile, NULL);
    _ASSERTE(-1 != dwFileSize);
    LPVOID pvData = NULL;
    //根据文件大小分配内存
    HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, dwFileSize);
    _ASSERTE(NULL != hGlobal);
    pvData = GlobalLock(hGlobal);
    _ASSERTE(NULL != pvData);
    DWORD dwBytesRead = 0;
    //读取文件并存入全局内存
    BOOL bRead = ReadFile(hFile, pvData, dwFileSize, &dwBytesRead, NULL);
    _ASSERTE(FALSE != bRead);
    GlobalUnlock(hGlobal);
    CloseHandle(hFile);
    LPSTREAM pstm = NULL;
    // 通过全局内存创建 IStream* 的指针
    HRESULT hr = CreateStreamOnHGlobal(hGlobal, TRUE, &pstm);
    _ASSERTE(SUCCEEDED(hr) && pstm);
    //通过图形文件创建IPicture 对象
    if (gpPicture)
    gpPicture->Release();
    hr = OleLoadPicture(pstm, dwFileSize, FALSE, IID_IPicture, (LPVOID *)&gpPicture);
    _ASSERTE(SUCCEEDED(hr) && gpPicture);
    pstm->Release();
    HDC hdc;
    hdc=pDC->GetSafeHdc();
    if (gpPicture)
    {
    // 取得图片的宽和高
    long hmWidth;
    long hmHeight;
    gpPicture->get_Width(&hmWidth);
    gpPicture->get_Height(&hmHeight);
    //宽高转换为象素
    int nWidth = MulDiv(hmWidth, GetDeviceCaps(hdc, LOGPIXELSX), HIMETRIC_INCH);
    int nHeight = MulDiv(hmHeight, GetDeviceCaps(hdc, LOGPIXELSY), HIMETRIC_INCH);
    RECT rc;
    GetClientRect(&rc);/*取得客户区*/
    gpPicture->Render(hdc, x,y, (int)height*hmWidth/hmHeight,height, 0, hmHeight, hmWidth, -hmHeight, &rc);
    /*显示图片*/
    }}
      

  6.   

    楼上大哥,那么晚了还出谋划策,令我感激.唉,这要是在vb里真简单啊, 都有点怀念vb了 :)