我从远程数据库中获取了一个Base64字符串的位图,(encodedImage是用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)
);
Run Code Online (Sandbox Code Playgroud)
profileImage是我的ImageView
好的,但是我必须在显示我ImageView的布局之前调整此图像的大小.我必须将其调整为120x120.
有人能告诉我调整大小的代码吗?
我找到的示例无法应用于获得位图的base64字符串.
我需要仅使用文件名来显示图像,而不是使用资源ID.
ImageView imgView = new ImageView(this);
imgView.setBackgroundResource(R.drawable.img1);
Run Code Online (Sandbox Code Playgroud)
我在drawable文件夹中有图像img1.我希望从文件中显示该图像.
我怎样才能做到这一点?
我有一个文件路径字符串形式为"e:\ ...\xxx.jpg"如何从中创建一个drawable?