开发者

Serving PNG images over http to Three20 iPhone app

I'm trying to serve up png images from a Linux (c++ / Qt4.5.x) server daemon to an iPhone application that is using the Three20 framework - specifically I want to use the TTThumbsViewController view.

I managed to make any web browser view images with the following returned in my daemon when it "GET"s a request:

QTextStream os(socket);
os.setAutoDetectUnicode(true);
QByteArray base64 = array.toBase64();

os << "HTTP/1.1 200 Ok\r\n"
  "Host: software.local\r\n"
  "\r\n"
  "<html>"
  "<body>"
  "<img src=\"data:image/png;base64," << base64 << "\" />"
  "</body>";

where "array" is a png's image data; I'm typing something like:

  http://software.local:8080/test.png

in to the browser to view the image.

When I try and specify the same URL in my photo source class with something like

[MockPhoto alloc]
 initWithURL:@"http://software.local:8080/test.png"
 smallURL:@"http://software.local:8080/test.png"
 size:CGSizeMake(480, 320)] autorelease],
...

nothing is returned or displayed?

My question is really - if I put say test.png in a suitable directory on the Linux PC and start a web server (apache), then browse to "http://software.local/test.png I see the image as above, but the image was not embedded in the http header? I really can't figure out what the header should be to get this behaviour. If I set the URL in the above iPhone code so it loads the png from the apache server I see it in the TTThumbsViewController.

Any help would great, or better way to do this - I only开发者_StackOverflow中文版 have basic http experience, as you can see.


Your script isn't serving an image, it's serving html that will be interpreted by a browser. I've never used three20's framework but I bet they're expecting a png to returned as data, nt embedded into a html document. As the browser you are testing with understands html as well as raw image data, it will display the image fine.

To get this to work you will need to set the content-type header to 'image/png' and then send the image data. I don't know how to do this in QT though, sorry :(

Sam


I used to do this with PHP. Translate these headers into your QT echo string.

header('Last-Modified: ' . date('r'));
header('Accept-Ranges: bytes');
header('Content-Length: ' . $imageSize);
header('Content-Type: image/png');
print(file_get_contents($file));

Not too sure about base64 if it's necessary or not

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜