【发布时间】:2024-01-14 21:18:01
【问题描述】:
以下代码在 android studio 中:
Bitmap newImage = (Bitmap) MediaStore.Images.Media.getBitmap(this.getContentResolver() , data.getData());
im.setImageBitmap(newImage);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
newImage.compress(Bitmap.CompressFormat.JPEG , 100 , baos);
byte[] bytearrayimage = baos.toByteArray();
String encodeimage = URLEncoder.encode(Base64.encodeToString(bytearrayimage , Base64.DEFAULT) , "UTF-8");
Toast.makeText(getApplicationContext() , String.valueOf(encodeimage.length()) , Toast.LENGTH_SHORT).show();
try
{
JSONObject json = new JSONObject();
json.put("type" , "picprofile");
json.put("username" , username);
json.put("image" , encodeimage);
new ConnectServer().execute("https://estate.shikmelk.ir/api/android/upload.php" , json.toString());
}
catch (JSONException j)
{
j.printStackTrace();
}
创建编码图像base64的部分代码,下面的代码在php中:
$img = $json["image"];
$imgname = $username . "profile.jpg";
$fopen = fopen("../../main/picprofile/" . $imgname , "wb");
fwrite($fopen , base64_decode($img));
fclose($fopen);
up部分代码在php中并获取base64_encode图像并转换为jpg图像 但是当我显示图像时没有显示任何意义转换但不显示图像。
【问题讨论】:
-
$img = $json["image"];。请发布完整的php。没有人知道你是如何获得 $json 的。此外,没有人知道您如何发布 json。所以没什么好说的。