如何调整在Android的位图? [英] How to Resize a Bitmap in Android?

查看:117
本文介绍了如何调整在Android的位图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的远程数据库采取的Base64字符串的位图,(连接codeDIMAGE 是字符串再presenting使用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的我的布局前调整这一形象。我必须把它调整为120×120。

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

谁可以告诉我的code来调整呢?

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆