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.....
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.
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.
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.
A Binary Large Object ( BLOB ) is a MySQL data type that can store binary data such as images, multimedia, and PDF files.
You can use Picasso for load images easily. For example:
Picasso.with(getActivity()).load(url).into(imageView);
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With