从mysql-php(android)中检索图像

Tuf*_*fan 7 php mysql android android-imageview android-bitmap

我在图像表字段中有一个图像,我想在我的应用程序我的PHP页面使用该图像

$user = array();
$user["image"] = base64_encode($result["image"]);
// success
$response["success"] = 1;

// user node
$response["image_table"] = array();

array_push($response["image_table"], $user);
Run Code Online (Sandbox Code Playgroud)

当我在我的应用程序中使用该数组时,我使用此...

if (success == 1)
{
    address = json.getJSONArray(TAG_IMAGE_TABLE);
    for (int i = 0; i < address.length(); i++) {
    JSONObject c = address.getJSONObject(i);
    image = c.getString(TAG_IMAGE);

} 
Run Code Online (Sandbox Code Playgroud)

它给我的结果如

json response: {"success":1,"image_table":     [{"image":"iVBORw0KGgoAAA...................."
Run Code Online (Sandbox Code Playgroud)

当我在我的图像视图中使用此图像时,我会使用它

ImageView ivProperty = ((ImageView) myContentView.findViewById(R.id.image_property));

byte[] decodedString;
try {
        decodedString = Base64.decode(image, Base64.URL_SAFE);
        Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
        ivProperty.setImageBitmap(decodedByte);
    } catch (IOException e) {
// TODO Auto-generated catch block
        e.printStackTrace();
    }
Run Code Online (Sandbox Code Playgroud)

但它给了我空指针异常

我的logcat值是

03-27 10:10:44.355: E/AndroidRuntime(2391):   java.lang.NullPointerException: Input string was null.
03-27 10:10:44.355: E/AndroidRuntime(2391):     at com.big_property_info.Base64.decode(Base64.java:1242)
03-27 10:10:44.355: E/AndroidRuntime(2391):     at  com.big_property_info.MainActivityMap$GeocoderTask$2.getInfoContents(MainActivityMap.java:314)
Run Code Online (Sandbox Code Playgroud)

如何解决那个空指针异常...当我接收图像字符串.....

小智 1

您可以使用 Picasso 轻松加载图像。例如:

Picasso.with(getActivity()).load(url).into(imageView);
Run Code Online (Sandbox Code Playgroud)