已经有一个控件PICTUREHBITMAP hbmp;
hbmp = (HBITMAP)LoadImage(AfxGetInstanceHandle(),"C:\\Winnt\\kp2003_1M.bmp"/*"D:\\csoft\\NTOOLS\\00\\04\\HTML\\JPG\\001.jpg"*/,IMAGE_BITMAP,400,300,LR_LOADFROMFILE | LR_CREATEDIBSECTION); m_Pic1.SetBitmap(hbmp);但是我这样做显示.bmp没有问题,但是却无法显示.jpg格式的文件,请问大家谁知道如何
显示.jpg格式的文件?

解决方案 »

  1.   

    jpg和bmp格式当然不同了
    你可以看jpeg/mpeg编解码一书!
      

  2.   

    用CPictureEx,我就用它作的动态的显示JPG格式的图片效果很好
    http://www.codeproject.com/bitmap/pictureex.asp?target=cpictureex
      

  3.   

    HBITMAP,顾名思义,当然是用来bitmap格式的文件,jpg格式的文件不一样是压缩过的
      

  4.   

    abc_rain() ,请问这个CPictureEx类里边有没有 可以调整图片大小的函数啊?
      

  5.   

    你可以在Load和Draw函数里稍改一下就可以如下:
    CRect rcTemp;
    m_Picture[ID].SubclassDlgItem(145+ID,this);
    m_Picture[ID].GetClientRect(rcTemp);
    m_Picture[ID].Load(strFileNmae,rcTemp.Width(),rcTemp.Height());
    m_Picture[ID].Draw(rcTemp.Width(),rcTemp.Height());
      

  6.   

    BOOL CPictureEx::Load(LPCTSTR szFileName,int cx,int cy)
    {
    strFileName.Format("%s",szFileName);
    CFile file;
    HGLOBAL hGlobal;
    DWORD dwSize; if (!file.Open(szFileName,
    CFile::modeRead | 
    CFile::shareDenyWrite) )
    {
    TRACE(_T("Load (file): Error opening file %s\n"),szFileName);
    return FALSE;
    }; dwSize = file.GetLength();
    hGlobal = GlobalAlloc(GMEM_MOVEABLE | GMEM_NODISCARD,dwSize);
    if (!hGlobal)
    {
    TRACE(_T("Load (file): Error allocating memory\n"));
    return FALSE;
    };

    char *pData = reinterpret_cast<char*>(GlobalLock(hGlobal));
    if (!pData)
    {
    TRACE(_T("Load (file): Error locking memory\n"));
    GlobalFree(hGlobal);
    return FALSE;
    }; TRY
    {
    file.Read(pData,dwSize);
    }
    CATCH(CFileException, e);                                          
    {
    TRACE(_T("Load (file): An exception occured while reading the file %s\n"),
    szFileName);
    GlobalFree(hGlobal);
    e->Delete();
    file.Close();
    return FALSE;
    }
    END_CATCH
    GlobalUnlock(hGlobal);
    file.Close(); BOOL bRetValue = Load(hGlobal,dwSize,cx,cy);
    GlobalFree(hGlobal);
    return bRetValue;
    }BOOL CPictureEx::Draw(int cx,int cy)
    {
    if (!m_bIsInitialized)
    {
    TRACE(_T("Call one of the CPictureEx::Load() member functions before calling Draw()\n"));
    return FALSE;
    }; if (IsAnimatedGIF())
    {
    // the picture needs animation
    // we'll start the thread that will handle it for us

    unsigned int nDummy;
    m_hThread = (HANDLE) _beginthreadex(NULL,0,_ThreadAnimation,this,
    CREATE_SUSPENDED,&nDummy);
    if (!m_hThread)
    {
    TRACE(_T("Draw: Couldn't start a GIF animation thread\n"));
    return FALSE;

    else 
    ResumeThread(m_hThread);

    else
    {
    if (m_pPicture)
    {
    long hmWidth;
    long hmHeight;
    m_pPicture->get_Width(&hmWidth);
    m_pPicture->get_Height(&hmHeight);
    if(cx==0)
    {
    if (m_pPicture->Render(m_hMemDC, 0, 0, m_PictureSize.cx , m_PictureSize.cy,  0, hmHeight, hmWidth, -hmHeight, NULL) == S_OK)
    {
    Invalidate(FALSE);
    return TRUE;
    };
    }
    if (m_pPicture->Render(m_hMemDC, 0, 0, cx, cy,  0, hmHeight, hmWidth, -hmHeight, NULL) == S_OK)
    {
    Invalidate(FALSE);
    return TRUE;
    };
    };
    }; return FALSE;
    }
    BOOL CPictureEx::Load(HGLOBAL hGlobal, DWORD dwSize,int cx,int cy)
    {
    IStream *pStream = NULL;
    UnLoad(); if (!(m_pRawData = reinterpret_cast<unsigned char*> (GlobalLock(hGlobal))) )
    {
    TRACE(_T("Load: Error locking memory\n"));
    return FALSE;
    }; m_nDataSize = dwSize;
    m_pGIFHeader = reinterpret_cast<TGIFHeader *> (m_pRawData); if ((memcmp(&m_pGIFHeader->m_cSignature,"GIF",3) != 0) &&
    ((memcmp(&m_pGIFHeader->m_cVersion,"87a",3) != 0) ||
     (memcmp(&m_pGIFHeader->m_cVersion,"89a",3) != 0)) )
    {
    // it's neither GIF87a nor GIF89a
    // do the default processing // clear GIF variables
    m_pRawData = NULL;
    GlobalUnlock(hGlobal); // don't delete memory on object's release
    if (CreateStreamOnHGlobal(hGlobal,FALSE,&pStream) != S_OK)
    return FALSE; if (OleLoadPicture(pStream,dwSize,FALSE,IID_IPicture,
    reinterpret_cast<LPVOID *>(&m_pPicture)) != S_OK)
    {
    pStream->Release();
    return FALSE;
    };
    pStream->Release(); // store picture's size long hmWidth;
    long hmHeight;
    m_pPicture->get_Width(&hmWidth);
    m_pPicture->get_Height(&hmHeight); HDC hDC = ::GetDC(m_hWnd);
    m_PictureSize.cx = MulDiv(hmWidth, GetDeviceCaps(hDC,LOGPIXELSX), 2540);
    m_PictureSize.cy = MulDiv(hmHeight, GetDeviceCaps(hDC,LOGPIXELSY), 2540);
    ::ReleaseDC(m_hWnd,hDC);
    }
    else
    {
    // it's a GIF
    m_bIsGIF = TRUE;
    m_pGIFLSDescriptor = reinterpret_cast<TGIFLSDescriptor *>
    (m_pRawData + sizeof(TGIFHeader));
    if (m_pGIFLSDescriptor->GetPackedValue(LSD_PACKED_GLOBALCT) == 1)
    {
    // calculate the globat color table size
    m_nGlobalCTSize = static_cast<int>
    (3* (1 << (m_pGIFLSDescriptor->GetPackedValue(LSD_PACKED_GLOBALCTSIZE)+1)));
    // get the background color if GCT is present
    unsigned char *pBkClr = m_pRawData + sizeof(TGIFHeader) + 
    sizeof(TGIFLSDescriptor) + 3*m_pGIFLSDescriptor->m_cBkIndex;
    m_clrBackground = RGB(pBkClr[0],pBkClr[1],pBkClr[2]);
    }; // store the picture's size
    m_PictureSize.cx = m_pGIFLSDescriptor->m_wWidth;
    m_PictureSize.cy = m_pGIFLSDescriptor->m_wHeight; // determine frame count for this picture
    UINT nFrameCount=0;
    ResetDataPointer();
    while (SkipNextGraphicBlock())
    nFrameCount++;#ifdef GIF_TRACING
    TRACE(
    _T(" -= GIF encountered\n"
       "Logical Screen dimensions = %dx%d\n"
       "Global color table = %d\n"
       "Color depth = %d\n"
       "Sort flag = %d\n"
       "Size of Global Color Table = %d\n"
       "Background color index = %d\n"
       "Pixel aspect ratio = %d\n"
       "Frame count = %d\n"
       "Background color = %06Xh\n\n"
      ),
    m_pGIFLSDescriptor->m_wWidth,
    m_pGIFLSDescriptor->m_wHeight,
    m_pGIFLSDescriptor->GetPackedValue(LSD_PACKED_GLOBALCT),
    m_pGIFLSDescriptor->GetPackedValue(LSD_PACKED_CRESOLUTION),
    m_pGIFLSDescriptor->GetPackedValue(LSD_PACKED_SORT),
    m_pGIFLSDescriptor->GetPackedValue(LSD_PACKED_GLOBALCTSIZE),
    m_pGIFLSDescriptor->m_cBkIndex,
    m_pGIFLSDescriptor->m_cPixelAspect,
    nFrameCount,
    m_clrBackground
    );
    EnumGIFBlocks();
    #endif if (nFrameCount == 0) // it's an empty GIF!
    {
    m_pRawData = NULL;
    GlobalUnlock(hGlobal);
    return FALSE;
    }; // now check the frame count
    // if there's only one frame, no need to animate this GIF
    // therefore, treat it like any other pic if (nFrameCount == 1)
    {
    // clear GIF variables
    m_pRawData = NULL;
    GlobalUnlock(hGlobal); // don't delete memory on object's release
    if (CreateStreamOnHGlobal(hGlobal,FALSE,&pStream) != S_OK)
    return FALSE; if (OleLoadPicture(pStream,dwSize,FALSE,IID_IPicture,
    (LPVOID *)&m_pPicture) != S_OK)
    {
    pStream->Release();
    return FALSE;
    }; pStream->Release();
    }
    else
    {
    // if, on the contrary, there are several frames
    // then store separate frames in an array TFrame frame;
    UINT nBlockLen;
    HGLOBAL hFrameData;
    UINT nCurFrame = 0; ResetDataPointer();
    while (hFrameData = GetNextGraphicBlock(&nBlockLen,
    &frame.m_nDelay, &frame.m_frameSize,
    &frame.m_frameOffset, &frame.m_nDisposal) )
    {
    #ifdef GIF_TRACING
    //////////////////////////////////////////////
    // uncomment the following strings if you want 
    // to write separate frames on disk
    //
    // CString szName;
    // szName.Format(_T("%.4d.gif"),nCurFrame);
    // WriteDataOnDisk(szName,hFrameData,nBlockLen);
    // nCurFrame++;
    #endif // GIF_TRACING IStream *pStream = NULL; // delete memory on object's release
    if (CreateStreamOnHGlobal(hFrameData,TRUE,&pStream) != S_OK)
    {
    GlobalFree(hFrameData);
    continue;
    }; if (OleLoadPicture(pStream,nBlockLen,FALSE,
    IID_IPicture,
    reinterpret_cast<LPVOID *>(&frame.m_pPicture)) != S_OK)
    {
    pStream->Release();
    continue;
    };
    pStream->Release();

    // everything went well, add this frame
    m_arrFrames.push_back(frame);
    }; // clean after ourselves
    m_pRawData = NULL;
    GlobalUnlock(hGlobal); if (m_arrFrames.empty()) // couldn't load any frames
    return FALSE;
    };
    }; // if (!IsGIF...
          if(cx==0)
      {
      return PrepareDC(m_PictureSize.cx ,m_PictureSize.cy);
      }
         return PrepareDC(cx,cy);
    //    return TRUE;
    }
      

  7.   

    从网上下载一个库吧,这个库做图像处理不错
    http://www.vchelp.net/vchelp/file2002_4/flib.asp?type_id=18&class_id=1&cata_id=12&article_id=907