Get image from mysql-php (android)

I have an image in the image table field and I want to use this image in my application my php page

$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 this array in my application 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); } 

he gives me the result as

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

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

 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 this gives me a null pointer exception

My logcat values

 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 this null pointer exception ... when I get the image string .....

+7
android php mysql android-bitmap android-imageview
source share
5 answers

You can easily use Picasso to upload images. For example:

 Picasso.with(getActivity()).load(url).into(imageView); 
+1
source share

Mark it . 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. 

Mark the link for the document on github.

+1
source share

You need to check your string whether it is null or not.

  ImageView ivProperty = ((ImageView) myContentView.findViewById(R.id.image_property)); byte[] decodedString; try { if (image!=null&&!image.equalsIgnoreCase("")) { 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(); } 
0
source share

There may be a problem due to the character set used for encoding and decoding in php and android

Use the same character set for both ends for encoding and decoding image data.

link to solve your problem fooobar.com/questions/537192 / ...

0
source share

If you get the image in a Base64 string, you can decode it as follows:

 byte[] data = Base64.decode(base64, Base64.DEFAULT); String text = new String(data, "UTF-8"); 

Or you can also get the link from the server and use the code below to show it on the image.

 if (imageUrl != null && isImageUrl) { Picasso.with(getApplicationContext()).load(Constants.IMG_URL + imageUrl).resize(150, 100).centerInside().into(ivActionHome); } 
0
source share

All Articles