我正在从网址下载图片并在我的Android应用程序上显示,但我无法根据我的要求调整图片大小。
private Bitmap decodeFile(File f) {
try {
//Decode image size
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
FileInputStream stream1 = new FileInputStream(f);
BitmapFactory.decodeStream(stream1, null, o);
stream1.close();
//Find the correct scale value. It should be the power of 2.
// Set width/height of recreated image
final int REQUIRED_SIZE = 285;
int width_tmp = o.outWidth, height_tmp = o.outHeight;
int scale = 1;
while (true) {
if (width_tmp / 2 < REQUIRED_SIZE || height_tmp / 2 < REQUIRED_SIZE)
break;
width_tmp /= 1;
height_tmp /= 1;
scale *= 2;
}
//decode with current scale values
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize = scale;
FileInputStream stream2 = new FileInputStream(f);
Bitmap bitmap = BitmapFactory.decodeStream(stream2, null, o2);
stream2.close();
return bitmap;
} catch (FileNotFoundException e) {
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
现在任何人都可以告诉我如何将图像大小调整为250 * 250像素 也提前还要
答案 0 :(得分:1)
尝试并使用Picasso库 - http://square.github.io/picasso/。
使用和集成相当容易,并且有一个resize方法正是这样做的。
Picasso.with(context).load(url).resize(250, 250).centerCrop().into(imageView);
你基本上放了&#39; url&#39;你的网址。