How to Resize a Bitmap in Android?

2018-12-31 05:52发布

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.

13条回答
浪荡孟婆
2楼-- · 2018-12-31 06:37

As of API 19, Bitmap setWidth(int width) and setHeight(int height) exist. http://developer.android.com/reference/android/graphics/Bitmap.html

查看更多
登录 后发表回答