Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve image from mysql-php(android)

i have a image in image table field and i want to use that image in my app my php page is

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

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

array_push($response["image_table"], $user);

when i use that array in my app i use this...

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);

} 

it gives me result like

json response: {"success":1,"image_table":     [{"image":"iVBORw0KGgoAAA...................."

when i use this image in my image view i use this like

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();
    }

But It Gives Me null pointer exception

my logcat values are

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)

How to solve that null pointer exception ...when i m receiving image string.....

like image 587
Tufan Avatar asked Mar 27 '15 14:03

Tufan


People also ask

How can I download image from MySQL database using PHP?

php file handles the image upload and database insertion process. Check whether the user selects an image file to upload. Retrieve the content of image file by the tmp_name using PHP file_get_contents() function. Insert the binary content of the image in the database using PHP and MySQL.

How fetch image from database in PHP and display in form?

To get a different image from the DB you simply change the id get parameter: <img src="getImage. php? id=1" width="175" height="200" /> <img src="getImage.

How display all images from database in PHP?

Explanation of PHP code: We are first selecting the records from the table in the $query variable. Then the $result will execute the query. While loop is used to fetch all the records in the $data to fetch the image from the database. And finally, the fetched images are displayed with the help of the <img> tag.

Can MySQL store images?

A Binary Large Object ( BLOB ) is a MySQL data type that can store binary data such as images, multimedia, and PDF files.


2 Answers

You can use Picasso for load images easily. For example:

Picasso.with(getActivity()).load(url).into(imageView);
like image 81
parik dhakan Avatar answered Oct 13 '22 11:10

parik dhakan


Check this. Its image downloader library and easy to implement.

DisplayImageOptions imageOptions;
ImageLoader imageLoader; 

     imageOptions = new DisplayImageOptions.Builder().showImageForEmptyUri(R.drawable
                    .logo_image).showImageOnFail(R.drawable.logo_image).cacheInMemory(true)
                    .cacheOnDisk(true)
                    .build();
            imageLoader = ImageLoader.getInstance();
            imageLoader.init(ImageLoaderConfiguration.createDefault(getActivity()));

imageLoader.displayImage(uri, imageView, imageOptions);
//Where uri is url of imageview stored in server. imageview is Imageview in which you want to show image. 

Check out link for document in github.

like image 24
Shvet Avatar answered Oct 13 '22 11:10

Shvet