Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Resize a Bitmap in Android?

I have a bitmap taken of a Base64 String from my remote database, (encodedImage is the string representing the image with Base64):

profileImage = (ImageView)findViewById(R.id.profileImage);  byte[] imageAsBytes=null; try {     imageAsBytes = Base64.decode(encodedImage.getBytes()); } catch (IOException e) {e.printStackTrace();}  profileImage.setImageBitmap(     BitmapFactory.decodeByteArray(imageAsBytes, 0, imageAsBytes.length) ); 

profileImage is my ImageView

Ok, but I have to resize this image before showing it on my ImageView of my layout. I have to resize it to 120x120.

Can someone tell me the code to resize it?

The examples I found could not be applied to a base64 string obtained bitmap.

like image 723
NullPointerException Avatar asked Jan 29 '11 15:01

NullPointerException


People also ask

How do I adjust photos on Android?

Tap the image you want to adjust. You can adjust the size of an image or rotate it: Resize: Touch and drag the squares along the edges. Rotate: Touch and drag the circle attached to the image.


1 Answers

Change:

profileImage.setImageBitmap(     BitmapFactory.decodeByteArray(imageAsBytes, 0, imageAsBytes.length) 

To:

Bitmap b = BitmapFactory.decodeByteArray(imageAsBytes, 0, imageAsBytes.length) profileImage.setImageBitmap(Bitmap.createScaledBitmap(b, 120, 120, false)); 
like image 187
user432209 Avatar answered Sep 22 '22 15:09

user432209