Php 如何将同一文件夹中的一些图像发送到android,以及android客户端如何解码这些数据流?
我已经用android实现了一个cbir程序。基本框架是:Php 如何将同一文件夹中的一些图像发送到android,以及android客户端如何解码这些数据流?,php,android,image,Php,Android,Image,我已经用android实现了一个cbir程序。基本框架是: 使用android摄像头拍摄照片并上传到wamp服务器 调用检索引擎并将一些检索到的图像(例如10个图像)存储在名为“./output/”的文件夹中 Php将结果图像发送到android进行显示 我的问题是如何将这些图像(10张左右)发送到android,以及android如何接收和解码这些图像。 在服务器端,php脚本如下所示: <?php # ..... #function for streaming file to
<?php
# .....
#function for streaming file to client
function streamFile($location, $filename, $mimeType='application/octet-stream')
{ if(!file_exists($location))
{ header ("HTTP/1.0 404 Not Found");
return;
}
$size=filesize($location);
$time=date('r',filemtime($location));
#html response header
header('Content-Description: File Transfer');
header("Content-Type: $mimeType");
header('Cache-Control: public, must-revalidate, max-age=0');
header('Pragma: no-cache');
header('Accept-Ranges: bytes');
header('Content-Length:'.($size));
header("Content-Disposition: inline; filename=$filename");
header("Content-Transfer-Encoding: binary\n");
header("Last-Modified: $time");
header('Connection: close');
ob_clean();
flush();
readfile($location);
}
# -------------------------------------------------------
# Main script
# -------------------------------------------------------
# test if the retrieved image are stored in the folder
$processed_photo_output_path = "./output"
$num_files = count(glob($_SERVER['DOCUMENT_ROOT'].'/output/*.png'));
while($num_files < 10){
usleep(100000);
}
usleep(100000);
% send the files in the while loop.
$list = scandir("/output/*.png");
$i = $num_files;
for(; $i > 0; $i--){
streamFile($list[i], $list[i], "application/octet-stream");
}
?>
我已经解决了这个问题。我修改了发送图片URL的计划,而不是将图片本身发送到android端。URL存储在mysql中,并以Json格式传递。sidnote:
return
?你的意思是退出,对吗?我已经解决了这个问题!如果你有这个问题的答案,请回答下面的问题。
//get image result from server and display it in result view
void getResultImage(HttpURLConnection conn){
// retrieve the response from server
InputStream is;
try {
is = conn.getInputStream();
//get result image from server
mResultView.resultImage = BitmapFactory.decodeStream(is);
is.close();
mResultView.IsShowingResult = true;
} catch (IOException e) {
Log.e(TAG,e.toString());
e.printStackTrace();
}
}