我正在尝试将 Linux (c++ / Qt4.5.x) 服务器守护程序中的 png 图像提供给使用 Three20 框架的 iPhone 应用程序 - 特别是我想使用 TTThumbsViewController 视图。
我设法让任何网络浏览器查看图像,当它“GET”请求时,我的守护进程中返回以下内容:
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>";
其中“array”是 png 的图像数据;我正在浏览器中输入类似:
http://software.local:8080/test.png
来查看图像。
当我尝试在照片源类中指定相同的 URL 时,不会
[MockPhoto alloc]
initWithURL:@"http://software.local:8080/test.png"
smallURL:@"http://software.local:8080/test.png"
size:CGSizeMake(480, 320)] autorelease],
...
返回或显示任何内容?
我的问题是真的 - 如果我将 test.png 放在 Linux PC 上的合适目录中并启动 Web 服务器(apache),然后浏览到“http://software.local/test.png 我看到了上面的图像,但是图像没有嵌入到http标头中?我真的不知道标头是什么?如果我在上面的 iPhone 代码中设置 URL,那么它会从 apache 服务器加载 png,我会在 TTThumbsViewController 中看到它
,或者更好的方法来做到这一点 - 我只有基本的 http。经验,如你所见。
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 have basic http experience, as you can see.
发布评论
评论(2)
您的脚本不提供图像,而是提供将由浏览器解释的 html。我从未使用过 Three20 的框架,但我敢打赌他们期望将 png 作为数据返回,而不是嵌入到 html 文档中。由于您正在测试的浏览器可以理解 html 以及原始图像数据,因此它将很好地显示图像。
要使其正常工作,您需要将内容类型标头设置为“image/png”,然后发送图像数据。我不知道如何在 QT 中执行此操作,抱歉:(
Sam
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
我以前用 PHP 做过这个。将这些标头翻译成您的 QT echo 字符串。
不太确定base64是否有必要
I used to do this with PHP. Translate these headers into your QT echo string.
Not too sure about base64 if it's necessary or not