これは、データと共に画像を取得するために行ったことです。私はそれが誰かを助けることができるならばそれを投稿する。
これは、サーバー側でデータを送信するPHPスクリプトの一部です:
$i=0;
//$sql contains the result from the query of the data
while($row=mysql_fetch_array($sql)){
$output[]=$row;
//Here we fetch the image from the files table
$query = "SELECT path, type FROM FILES WHERE poi_id = '" . mysql_real_escape_string(trim($output[$i][0])) . "'";
$r = mysql_query($query);
$img = mysql_fetch_array($r);
$bin = base64_encode_image($img[0]);
//Let's append the image and the type to the data output.
$output[$i]['img'] = $bin;
$output[$i]['type'] = $img[1];
$i++;
}
//This method sends the response to the Android app
//You can just use echo(json_encode($output));
RestUtils::sendResponse(200, json_encode($output), 'application/json');
そして、Androidアプリで、JSONを解析した後、あなたがにイメージとしてbase64文字列を保存することができますこのようなファイルシステム:
public void createImage(String image, String name){
try{
byte[] imageAsBytes = Base64.decode(image.getBytes(), Base64.DEFAULT);
Bitmap img_bitmap = BitmapFactory.decodeByteArray(imageAsBytes, 0, imageAsBytes.length);
FileOutputStream fos = openFileOutput(name, Context.MODE_WORLD_READABLE);
img_bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.flush();
fos.close();
}
catch(Exception e){
e.printStackTrace();
}
}
私は、base64について読んで、私は、pHを見ましたそれを行うp関数。しかし、どのようにイメージをPHP変数として取得しますか?ファイル機能では?それとももっと複雑なのでしょうか? DBでBLOBを使用せず、イメージをファイルシステムに格納したいと思っています。 – ferguior
私はファイルシステムにファイルを格納することによってそれを使用していません。私は、Webサービスが私にbase64で情報を与えたときにしか使用していません。 –