How do I convert an image into a buffer so that I can send it over using socket programming? I'm using C++ socket programming. I am also using QT for my Gui.
Also, after sending it over through the socket, how do I put that image back together so it can become a file again?
If someone could put up some sample code that would be great :)
I was looking around and found something about rfile but still not going through my head.
tyty
如果您使用的是Qt,请使用QImageWriter和QImageReader并让它们直接处理套接字,从而避免需要临时文件。
Assuming that you want to send an image as a file,
here is pseudocode to send it through a TCP connection.
Client A
Set up a connection
Open a file in binary mode
Loop:
read/load N bytes in a buffer
send(buffer)
Close file
Close connection
Client B
Listen and accept a connection
Create a new file in binary mode
Loop:
n = read(buffer)
write n bytes in the file
Close file
Close connection
I figured this out as well and wrote down what I did. You can find the description here: http://hanckmann.net/?q=node/44 . It is fine to download and use the examples there!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.