如何在从服务器设置图像后刷新ImageView在我的情况下它不更新ImageView

时间:2015-08-23 20:25:00

标签: php android mysql image

问题在于 当我从图库中获取图片并将其设置为图像视图时, 然后它被设置,但当我关闭该活动并再次打开它时, 它显示我以前的图像不是更新的图像, 我的代码将图像完美地发送到服务器并将其保存到服务器, 也在MYSQL中。 但是,当我尝试从特定的URL检索图像时,它不是 检索图像.....

当我刷新服务器上保存更新图像的URL时, 它正在向我展示imageView上的更新图像。

这是我的downloadimage类......



package com.tut.app;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.util.Log;
import android.widget.ImageView;
import android.widget.Toast;

import java.io.InputStream;



public class DownloadImageTask extends AsyncTask<String, Void, Bitmap>
{
    private ImageView imgView;

    public DownloadImageTask(ImageView imageView)
    {
        this.imgView = imageView;

    }

    protected Bitmap doInBackground(String... urls) {
        String urldisplay = urls[0];
        Bitmap mIcon11 = null;
        try {
            InputStream in = new java.net.URL(urldisplay).openStream();
            mIcon11 = BitmapFactory.decodeStream(in);
        } catch (Exception e) {
            Log.e(" Error coming data ", e.getMessage());
            e.printStackTrace();
        }
        return mIcon11;
    }

    @Override
    protected void onPostExecute(Bitmap result)
    {
        Log.e("result ", String.valueOf(result));
        this.imgView.setImageBitmap(result);
    }

}
&#13;
&#13;
&#13;

这是我的PHP脚本来设置图像并将其更新保存到数据库

&#13;
&#13;
<?php

    // connect to mysql database
    $con = mysql_connect("127.0.0.1","root","pass123");
    if (!$con){
        die('Could not connect: ' . mysql_error());
    }
    mysql_select_db("TestDatabase", $con); // name of your database

    //check if "image" abd "CustomerID" is set

    if(isset($_POST["image"]) && isset($_POST["CustomerID"])) {
        $data = $_POST["image"];
        $CustomerID = $_POST["CustomerID"];
        $ImageName = $CustomerID.".jpg";
        $filePath = "images/".$ImageName; // path of the file to store
        echo "file ".$filePath;
        // check if file exits
        if (file_exists($filePath)) {
            unlink($filePath); // delete the old file
        }
        // create a new empty file
        $myfile = fopen($filePath, "w") or die("Unable to open file!");
        // add data to that file
        file_put_contents($filePath, base64_decode($data));

        // update the Customer table with new image name.
        mysql_query("UPDATE Customers SET imageName='$ImageName' WHERE id='$CustomerID'")
            or die('Could not save Image Name: ' . mysql_error());

    } else {
        echo 'not set';
    }
    // close the connection
    mysql_close($con);

?>
&#13;
&#13;
&#13;

0 个答案:

没有答案