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.
Change:
To:
Bitmap Resize based on Any Display size
Someone asked how to keep aspect ratio in this situation:
Calculate the factor you are using for scaling and use it for both dimensions. Let´s say you want an image to be 20% of the screen in height
for getting the screen resolution you have this solution: Get screen dimensions in pixels
EDIT: as suggested by by @aveschini, I have added
bm.recycle();
for memory leaks. Please note that in case if you are using the previous object for some other purposes, then handle accordingly.