[英]Scaled Bitmap is failed in Samsung Galaxy S3
Thanks for earlier support. 感谢您的早期支持。 Currently I am working on a Project where i need to resize images downloaded from Server.
目前,我正在一个项目中,我需要调整从服务器下载的图像的大小。 Images have a large resolution so i want to resize as per screenSize of Device.
图像具有较大的分辨率,所以我想根据设备的screenSize调整大小。 Here below is my code.
下面是我的代码。 Please have a look.
请看一看。
// 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();
But once i get the desirable scale it finds a null-bitmap at the end of the Code in case of Samsung Galaxy S3. 但是,一旦获得理想的比例,对于三星Galaxy S3,它会在代码末尾找到一个空位图。 It's working fine on Emulator, Samsung galaxy S4, Htc one v. I am also worried about generalization of the Code so it should be working on Every device.
在Emulator,Samsung galaxy S4,Htc one v上运行正常。我也担心该代码的泛化,因此它应该在每台设备上都可以使用。
If anybody had experience for such a Problem Please let me know. 如果有人有遇到此类问题的经验,请告诉我。
what's your REQUIRED_SIZE value? 您的REQUIRED_SIZE值是多少? set it 1024. Because may be that was due to Out of memory exception while decode large resolution image.
将其设置为1024。可能是由于解码高分辨率图像时内存不足异常所致。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.