1
感谢您的支持。 目前我正在从事一个项目,我需要调整从服务器下载的图像的大小。图像具有较大的分辨率,所以我想根据设备的screenSize调整大小。下面是我的代码。请看一看。三星Galaxy S3缩放位图失败
// decode image size initially
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.
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 /= 2;
height_tmp /= 2;
scale *= 2;
}
// decode with inSampleSize
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize = scale;
FileInputStream stream2 = new FileInputStream(f);
Bitmap bitmap = BitmapFactory.decodeStream(stream2, null, o2);
stream2.close();
但是,一旦我得到理想的规模,它会发现在三星Galaxy S3的情况下代码结束时的空位图。它在Emulator,Samsung Galaxy S4,Htc one v上工作得很好,我也担心Code的泛化,因此它应该适用于所有设备。
如果有人有这样的问题的经验请让我知道。
在三星Galaxy S3的情况下,它是720。 –