讀取 顯示 jpeg stream 視頻流

來源:互聯網
上載者:User

char url[1000] = "http://192.168.131.129:8080/?action=snapshot";
 
   
    //cout<<"目標地址 URL:"<<url<<endl;
    
        unsigned char *buffer=new BYTE[100000];
         
    DWORD bytes_read;
    HINTERNET internet= InternetOpen("HTTP Downloader",INTERNET_OPEN_TYPE_PRECONFIG,
     NULL,NULL, NULL);
    
    if( !internet )
    return ;
    
    HINTERNET file_handle = InternetOpenUrl(internet, url, NULL, 0, INTERNET_FLAG_RELOAD, 0);
    if( !file_handle)
    
       return ;
      void *pImageMemory=GlobalLock(buffer);
    BOOL b = InternetReadFile(file_handle,pImageMemory,100000,&bytes_read);
    GlobalUnlock(pImageMemory); //解鎖記憶體
    if(!b)
     return;
    
    CDC* pDC = GetDlgItem(IDC_ShowImg) ->GetDC();
    
    HDC hDC = pDC ->GetSafeHdc();
    CRect rect;
    GetDlgItem(IDC_ShowImg) ->GetClientRect( &rect );
   
    

    IStream *pIStream;//建立一個IStream介面指標,用來儲存圖片流
    IPicture *pIPicture;//建立一個IPicture介面指標,表示圖片對象
                CreateStreamOnHGlobal(pImageMemory, false, &pIStream); //用全域記憶體初使化IStream介面指標
    OleLoadPicture(pIStream, 0, false, IID_IPicture, (LPVOID*)&(pIPicture));//用OleLoadPicture獲得IPicture接

    long hmWidth;
       long hmHeight;

    pIPicture->get_Width(&hmWidth); //用介面方法獲得圖片的寬和高
    pIPicture->get_Height(&hmHeight);
                pIPicture->Render(hDC,0,0,640,480,0,hmHeight,hmWidth,-hmHeight,NULL);

                //HANDLE  hFile =CreateFile(_T(file_handle),   GENERIC_READ,   0,   NULL,   OPEN_EXISTING,   0,   NULL);  
         // buffer[bytes_read]=0;
   // delete []buffer;
    
    GlobalFree(pImageMemory); //釋放全域記憶體
                pIStream->Release(); //釋放pIStream
                pIPicture->Release(); //釋放pIPicture

    InternetCloseHandle(internet);

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.