读取 显示 jpeg stream 视频流

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);

你可能感兴趣的:(Stream,File,null,url,buffer,internet)