Loading JPEG files

Hi,

Can somebody tell me how to load JPEG files at runtime.

I can load BMP files. But I don't know whether the same technique will work for JPEG files too.

Is the structure of BMP and JPEG the same

Along with this please help me with how to load Animated GIF files and simple GIF files.

Thanks


Answer this question

Loading JPEG files

  • Frank I. garcia

    Found none.Sad

  • Glandorf

    www.wotsit.com

  • Calvinator

    Thanks martin.

    You've done it this time [:}]

  • AmR EiSa

  • S. Allard

    I knew one solution.
    The below code supports GIF, BMP
    , JPG and so on.

    Have a Good Programming!!!

    -------------------------------------------------

    HRESULT LoadPicture(LPCTSTR szType, LPTSTR szID, char OverrideBPP,LPPICTURE* ppv)
    {
     HRSRC hRes;
     LPVOID pMem;
     HGLOBAL pGlobal;
     LPPICTURE pPic=0;
     LPSTREAM pStream=0;
     HBITMAP hBmp=0,hRetBmp;
     BITMAP bmp;
     HDC hDCDest,hDCSrc;
     DWORD dwSize;
     int file;
     DWORD dwRead,dwTotal;
     PICTDESC pd;
     if (!szID || !ppv) return E_INVALIDARG;
     if (!szType)
     {
      file=_topen(szID,_O_RDONLY | _O_BINARY);
      if (file==-1) goto Err;
      dwSize=_filelength(file);
      pGlobal=GlobalAlloc(0,dwSize);
      dwRead=0;dwTotal=0;
      
      while (dwTotal<dwSize){
       dwRead=_read(file,((LPBYTE)pGlobal)+dwTotal,512); //Read sector by sector
       if (!dwRead) {_close(file);goto Err;}
       dwTotal+=dwRead;
      }
      _close(file);
     } else {
      hRes=FindResource(NULL,szID,szType);
      if (!hRes) return NULL;
      pMem=LoadResource(NULL,hRes);
      if (!pMem) return NULL;
      dwSize=SizeofResource(NULL,hRes);

      pGlobal=GlobalAlloc(0,dwSize);
      memcpy(pGlobal,pMem,dwSize);
     }

     if (FAILED(CreateStreamOnHGlobal(pGlobal,FALSE,&pStream))) goto Err;
     
     if (FAILED(OleLoadPicture(pStream,dwSize,TRUE,IID_IPicture,(LPVOID*)&pPic))) goto Err;
     
     pStream->Release(); pStream=0;
     GlobalFree(pGlobal);pGlobal=0;
     if (OverrideBPP<=0) {
      *ppv=pPic;
     } else {

      if (FAILED(pPic->get_Handle((OLE_HANDLE*)&hBmp))) goto Err;
      hDCSrc=CreateCompatibleDC(0);
      GetObject(hBmp,sizeof(BITMAP),&bmp);
      hBmp=(HBITMAP)SelectObject(hDCSrc,hBmp);
      hRetBmp=CreateBitmap(bmp.bmWidth,bmp.bmHeight,1,OverrideBPP,NULL);
      hDCDest=CreateCompatibleDC(0);
      hRetBmp=(HBITMAP)SelectObject(hDCDest,hRetBmp);
      BitBlt(hDCDest,0,0,bmp.bmWidth,bmp.bmHeight,hDCSrc,0,0,SRCCOPY);
      SelectObject(hDCSrc,hBmp);
      hRetBmp=(HBITMAP)SelectObject(hDCDest,hRetBmp);
      DeleteDC(hDCSrc);hDCSrc=0;
      DeleteDC(hDCDest);hDCDest=0;
      pPic->Release();pPic=NULL;

      pd.cbSizeofstruct=sizeof(PICTDESC);
      pd.picType=PICTYPE_BITMAP;
      pd.bmp.hbitmap=hRetBmp;
      pd.bmp.hpal=NULL;
      if (FAILED(OleCreatePictureIndirect(&pd,IID_IPicture,TRUE,(LPVOID*)&pPic))) {DeleteObject(hRetBmp); return E_FAIL;}
     }
     return S_OK;
    Err:
     if (pStream) {pStream->Release();}
     if (pGlobal) GlobalFree(pGlobal);
     if (pPic) pPic->Release();
     if (hBmp) DeleteObject(hBmp);
     return E_FAIL;
    }

    //For use IPicture you can use
    HBITMAP LoadPictureEx(LPTSTR szFile)
    {
     HBITMAP hBmp;
     LPPICTURE pPic=NULL;
     if (FAILED(LoadPicture(NULL, szFile,0,&pPic)))
      goto Err;
     if (FAILED(pPic->get_Handle((OLE_HANDLE *)&hBmp)))
      goto Err;
     hBmp = (HBITMAP)CopyImage(hBmp,IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION);
     if (!hBmp)
      goto Err;
     pPic->Release();
     return hBmp;
    Err:
     if (pPic != NULL) pPic->Release();
     return NULL;
    }



  • vaibhavsaxena17

  • rashe

    Thanks

    Out of curiosity may I ask what is the file structure of a JPEG and a GIFIdea.

    Can't help it you know.Big Smile

  • Cadabuz

    Sorry its www.wotsit.org

  • Loading JPEG files