이것은 데이터와 함께 이미지를 가져온 것입니다. 나는 그것이 누군가를 도울 수있는 경우에 그것을 배치한다.
$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');
그리고 안드로이드 응용 프로그램에서 JSON을 파싱 한 후, 당신은에 대한 이미지로 base64로 문자열을 저장할 수 있습니다
이
는 서버 측에서 데이터를 전송하는 PHP 스크립트의 일부입니다 이 같은 파일 시스템 :
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();
}
}
나는베이스 64에 대해 읽고 난 산도를 보았다 그것을하는 p 함수. 하지만 어떻게 이미지를 PHP 변수로 가져 옵니까? 파일 기능? 아니면 그보다 더 복잡합니까? DB에서 BLOB를 사용하지 않고 파일 시스템에 이미지를 저장하는 것을 선호합니다. – ferguior
파일 시스템에 파일을 저장하여 사용하지 않았습니다. 나는 웹 서비스가 나에게 base64로 정보를 주었을 때만 사용했다. –