Re: read image from socket
Bob Friesenhahn <[email protected]> Tue, 27 Oct 2009 10:44:50 -0500 (CDT)
| Newsgroups | gmane.comp.video.graphicsmagick.apis |
|---|---|
| Message-ID | <[email protected]> |
On Tue, 20 Oct 2009, long wang wrote: > I have a question about the graphicsmagick api. How should I read a > image from a socket? Assuming that the code works as intended, if you pass an open stdio file handle via the ImageInfo file member, then it should be used for reading or writing. Under Unix, you would use fdopen() to create a FILE* from a socket file descriptor. > I'm writing a program which reads image from client via socket and > resizes the image then sends the new image back. But I found I > cannot read the image from socket. Did i miss something? You could use the ImageInfo->file member as I mention above, but unless the image data is very large, I recommend buffering the data in memory (and using BlobToImage() and ImageToBlob()), or if it is very large, buffering it to disk. The reason for this is that network sockets may expire (or get stuck) at any time so it is useful to simplify the data transfer and error handling to the maximum extent possible. Otherwise if the network becomes extremely slow then the GraphicsMagick API would appear to be hung and without a very nice way to terminate it (you would have to close the socket file descriptor while GraphicsMagick is using it and hope for the best). Bob -- Bob Friesenhahn [email protected], http://www.simplesystems.org/users/bfriesen/ GraphicsMagick Maintainer, http://www.GraphicsMagick.org/ ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference