Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android set bitmap to Imageview

Hi i have a string in Base64 format. I want to convert it ot a bitmap and then display it to an ImageView. This is the code:

ImageView user_image; Person person_object; @Override protected void onCreate(Bundle savedInstanceState) {     super.onCreate(savedInstanceState);     setContentView(R.layout.user_profile_screen);      // ImageViews     user_image = (ImageView) findViewById(R.id.userImageProfile);      Bundle data = getIntent().getExtras();     person_object = data.getParcelable("person_object");     // getPhoto() function returns a Base64 String     byte[] decodedString = Base64.decode(person_object.getPhoto(), Base64.DEFAULT);      Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);     user_image.setImageBitmap(decodedByte);     } 

This code get the Base64 String successfully and i do not get any error. But It does not display the image. What can be the problem? Thanks

like image 730
kgnkbyl Avatar asked Mar 10 '13 15:03

kgnkbyl


People also ask

How to set bitmap in android?

To create a bitmap from a resource, you use the BitmapFactory method decodeResource(): Bitmap bitmap = BitmapFactory. decodeResource(getResources(), R. drawable.

How do I get bitmap from ImageView?

Bitmap bm=((BitmapDrawable)imageView. getDrawable()). getBitmap(); Try having the image in all drawable qualities folders (drawable-hdpi/drawable-ldpi etc.)

What is ImageView in android studio?

Displays image resources, for example Bitmap or Drawable resources. ImageView is also commonly used to apply tints to an image and handle image scaling.


1 Answers

Please try this:

byte[] decodedString = Base64.decode(person_object.getPhoto(),Base64.NO_WRAP); InputStream inputStream  = new ByteArrayInputStream(decodedString); Bitmap bitmap  = BitmapFactory.decodeStream(inputStream); user_image.setImageBitmap(bitmap); 
like image 183
1218985 Avatar answered Sep 20 '22 17:09

1218985