我从远程数据库中获取了一个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字符串.
我已经采取并修改了一些代码,用于获得较大(500x500)位图图像的高质量抗锯齿小版本。显然,使用 Matrix 比使用 createScaledBitmap() 产生更高的质量。结果不是很令人印象深刻..我怀疑也许我犯了一个错误,特别是我不确定是否真的使用了期权。所以我将其更改inSampleSize = 1;为inSampleSize = 50;期望看到质量急剧下降,但没有任何变化。所以现在我怀疑选项被忽略了。这段代码能救出来吗?
我希望也许能找到某个版本的 createBitmap,它接受了 abitmap和一个options参数,但找不到。
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferQualityOverSpeed = true;
options.inJustDecodeBounds = false;
options.inDither = false;
options.inSampleSize = 1;
options.inScaled = false;
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmap bmpSource = BitmapFactory.decodeResource(getResources(), R.drawable.bigicon);
Matrix matrix = new Matrix();
matrix.postScale(.1f,.1f);
Bitmap scaledBitmap = Bitmap.createBitmap(bmpSource, 0, 0, bmpSource.getWidth(), bmpSource.getHeight(), matrix, true);
Run Code Online (Sandbox Code Playgroud)