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

听海拉拉 听海拉拉 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
本人不懂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)
...全文
评论 4
收藏 已收藏
分享
返回顶部
听海拉拉
脚本语言 37,737 成员 34,208 内容