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.
Scale based on aspect ratio:
To use height as base intead of width change to:
Scale a bitmap with a target maximum size and width, while maintaining aspect ratio:
try this this code :
I hope it's useful.
Try this: This function resizes a bitmap proportionally. When the last parameter is set to "X" the
newDimensionXorY
is treated as s new width and when set to "Y" a new height.If you already have a bitmap, you could use the following code to resize: