php - How to send some images in a same folder to android and how android client can decode these datastream? -
i have implemented cbir program using android. basic framework is:
- take picture using android camera , upload wamp server
- call retrieval engine , store retrieved images (for example 10 images) in folder, named './output/'
- php sends result images android displaying.
my question how send these images (10 more or less) android , how android receives , decodes these images. on server sider, php script looks like:
<?php # ..... #function streaming file 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 retrieved image stored in folder $processed_photo_output_path = "./output" $num_files = count(glob($_server['document_root'].'/output/*.png')); while($num_files < 10){ usleep(100000); } usleep(100000); % send files in while loop. $list = scandir("/output/*.png"); $i = $num_files; for(; $i > 0; $i--){ streamfile($list[i], $list[i], "application/octet-stream"); } ?>
the following code used on client side receive data. however, find if server sends 1 image, works well. if number of images more 1, crashes.
what should if server pushes 10 images client? suggestions appreciated.
//get image result server , display in result view void getresultimage(httpurlconnection conn){ // retrieve response server inputstream is; try { = conn.getinputstream(); //get result image server mresultview.resultimage = bitmapfactory.decodestream(is); is.close(); mresultview.isshowingresult = true; } catch (ioexception e) { log.e(tag,e.tostring()); e.printstacktrace(); } }
i have figured out problem. modify plan send urls of images rather image android side. urls stored in mysql , passed json format.
Comments
Post a Comment