怎么用C或C++实现以下python 语言描述

听海拉拉 2010-08-26 10:40:27
本人不懂python
需要用c++/c写一个客户端软件,像以下代码描述的一样。不知道怎么入手
#!/usr/bin/env python
import httplib #httplib modules for the HTTP interactions
from Tkinter import * #Tkinter modules for Windowing
from PIL import Image, ImageTk #Python Image Libraries, required for displaying jpegs
from time import sleep
import StringIO #For converting Stream from the server to IO for Image (PIL)
from StreamViewer import StreamViewer

'''Gets the file from the specified
host, port and location/query'''
def get(host,port,query):
h = httplib.HTTP(host, port)
h.putrequest('GET', query)
h.putheader('Host', host)
h.putheader('User-agent', 'python-httplib')
h.putheader('Content-type', 'image/jpeg')
h.endheaders()

(returncode, returnmsg, headers) = h.getreply()
print "return code:",returncode
print "return message:",returnmsg
print "headers:",headers
if returncode != 200:
print returncode, returnmsg
sys.exit()

f = h.getfile()
return f.read()

'''This is where we show the file on our StreamViewer'''
def streamfile(tbk, root):
f = get('127.0.0.1',80,'/?action=snapshot')
img=Image.open(StringIO.StringIO(f)) #convert to jpeg object from the stream
imagetk = ImageTk.PhotoImage(img) #Get a PhotoImage to pass to our Frame
tbk.addImage(imagetk) #Image added
root.update()


root = Tk()
tbk = StreamViewer(root)
#As much space as we need, no more, no less
#we change the root geometry to the size of the streaming jpg #As much space as we need, no more, no less

root.geometry("%dx%d+0+0" % (640, 480))
root.resizable(False,False)
'''It's our overrated slideshow viewer .. hehe'''
while(1):
streamfile(tbk,root)
from Tkinter import *

#########
class StreamViewer(Frame):
def __init__(self, root):
root.title("Test Application")
self.addFrame(root)

def addFrame(self,root):
frame = Frame(root, background="#FFFFFF")
self.addCanvas(frame)
frame.pack(fill=BOTH, expand=YES)

def addCanvas(self, frame):
self.canvas = Canvas(frame, background='#000000')
self.canvas.pack(fill=BOTH, expand=YES)
self.canvas.pack()

def addImage(self, photoimage):
self.canvas.create_image(640,480, image=photoimage,anchor=SE)
...全文
84 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
听海拉拉 2010-08-26
  • 打赏
  • 举报
回复
f = get('127.0.0.1',80,'/?action=snapshot')
里面的'/?action=snapshot'是何意?这个位置的参数是要来描述什么的?
听海拉拉 2010-08-26
  • 打赏
  • 举报
回复
用qt怎么实现呢
听海拉拉 2010-08-26
  • 打赏
  • 举报
回复
服务器端是用开源的mjpg-streamer 做的,输入网址可以看到视频。这个开源也提供了viewer.exe。输入网址和端口,也可以看见视频。俺也想用C++ or c来实现。
iambic 2010-08-26
  • 打赏
  • 举报
回复
就是用HTTP库把图片下下来,然后用GUI库显示出来吧。很简单了,把这两个种库的C++实现找到就可以了,比如Qt或者wxWidgets之类的都提供。

37,720

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

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