VC + + display a JPG image

Source: Internet
Author: User

BOOLCshowjpgdlg::showjpggif (cdc* pdc,cstring strpath,intXinty) {IStream*PStm;     CFileStatus Fstatus;     CFile file;    LONG CB; if(file. Open (Strpath,cfile::moderead) &&file. GetStatus (Strpath,fstatus) && (cb = fstatus.m_size)! =-1) {hglobal hglobal=GlobalAlloc (gmem_moveable, CB); LPVOID PvData=NULL; if(Hglobal! =NULL) {PvData=GlobalLock (HGLOBAL); if(PvData! =NULL) {file.                 Read (PvData, CB);                 GlobalUnlock (HGLOBAL); CreateStreamOnHGlobal (Hglobal, TRUE,&PStm); }        }    }    Else    {        return false; }    //displays pictures in JPEG and GIF format, GIF can only display one frame, and cannot display animations .//to display an animated GIF, use the active control//components. IPicture *ppic =nullptr; //load image from file stream    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); DoubleFx,fy; //Get Image Height and widthFX = (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); //Use render function display image        if(FAILED (Ppic->render (*pdc,x,y, (DWORD) FX, (DWORD) FY,0, hmheight,hmwidth,-hmheight,null)))  {Ppic-Release (); return false; } ppic-Release (); }     Else         return false; return true;}

2. Call
cdc* PDC = GetDlgItem (IDC_PICTRUE11)->getdc ();
Showjpggif (pdc,_t ("d.jpg"), 0,0);

VC + + display a JPG image

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.