HOWTO:实现从http读取并显示图像?

听海拉拉 2010-08-26 11:40:20
Hi ALL,
比如有一个web site http://127.0.0.1:8080/?action=stream&ignored.mjpg。要从上面读取jpeg的图像,并显示出来。
而且不断的读取,成视频流。
用c++怎么实现呢?或者MFC也行。
谢谢
...全文
92 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
听海拉拉 2010-08-26
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 binghuazh 的回复:]
搞个缓存,播放图片从缓存去数据,http读过来把数据扔缓存里面,注意同步

图片控件就是Picture啊 Image都有,mfc的

http就用socket send recv回来

gl
[/Quote]
有空帮忙改改
tks
// HttpTest.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "HttpTest.h"
#include <wininet.h>
#include <highgui.h>
#include <cv.h>


#pragma comment(lib, "Wininet.lib")
#pragma comment(lib, "jpeg.lib")
#pragma comment(lib,"CxImage.lib")
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// The one and only application object
void Download(char url[]);
CWinApp theApp;




using namespace std;

//BYTE * lpBmpData; //保存图像文件像素数据
//LONG ImageWidth; //图像宽度
//LONG ImageHeight; //图像高度
//PBITMAPINFO info; //文件信息头
//IplImage * temp;
//IplImage * pImg;
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;




//cout<<"nihao"<<endl;
char url[1000] = "http://192.168.131.129:8080/?action=snapshot";
while(1)
{
try
{
cout<<"目标地址 URL:"<<url<<endl;
Download(url);
cout<<"已经显示"<<endl;
}

catch(char *e)
{
cout<<e<<endl<<endl;
}

}
return nRetCode;
}


void Download(char url[])
{
char buffer[100000];
DWORD bytes_read;
HINTERNET internet= InternetOpen("HTTP Downloader",INTERNET_OPEN_TYPE_PRECONFIG,
NULL,NULL, NULL);

if( !internet )
throw "InternetOpen error!";

HINTERNET file_handle = InternetOpenUrl(internet, url, NULL, 0, INTERNET_FLAG_RELOAD, 0);
if( !file_handle)
throw "InternetOpenUrl error! - Maybe you should add Http:// or Ftp://";

BOOL b = InternetReadFile(file_handle,buffer,100000,&bytes_read);
if(!b)
throw "InternetReadFile error!";


buffer[bytes_read]=0;


InternetCloseHandle(internet);
}


听海拉拉 2010-08-26
  • 打赏
  • 举报
回复
tks
blingpro 2010-08-26
  • 打赏
  • 举报
回复
搞个缓存,播放图片从缓存去数据,http读过来把数据扔缓存里面,注意同步

图片控件就是Picture啊 Image都有,mfc的

http就用socket send recv回来

gl

33,311

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧