如何在 Android 中调整位图的大小? [英] How to Resize a Bitmap in Android?
本文介绍了如何在 Android 中调整位图的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从远程数据库中获取了 Base64 字符串的位图,(encodedImage
是表示带有 Base64 的图像的字符串):
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 是我的 ImageView
好的,但是在我的布局的 ImageView
上显示它之前,我必须调整它的大小.我必须将其调整为 120x120.
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?
我发现的示例无法应用于 base64 字符串获得的位图.
The examples I found could not be applied to a base64 string obtained bitmap.
推荐答案
更改:
profileImage.setImageBitmap(
BitmapFactory.decodeByteArray(imageAsBytes, 0, imageAsBytes.length)
致:
Bitmap b = BitmapFactory.decodeByteArray(imageAsBytes, 0, imageAsBytes.length)
profileImage.setImageBitmap(Bitmap.createScaledBitmap(b, 120, 120, false));
这篇关于如何在 Android 中调整位图的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文