在从 BitmapFactory.decodeStream(imagestream)
返回之前,我需要调整/缩小我从图库中选择的图像。当我选择大图像时,它会抛出 OutOfMemory Exception
。如何在从 decodeStream 返回图像之前调整图像大小?
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == IMAGE_PICKER_SELECT
&& resultCode == Activity.RESULT_OK) {
Uri selectedImage = data.getData();
InputStream imageStream = null;
try {
imageStream = getContentResolver().openInputStream(
selectedImage);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Bitmap bitmap = BitmapFactory.decodeStream(imageStream);
imgV.setImageBitmap(bitmap);
// sb = bitmap;
// imgSelected = true;
selectedImage = null;
imageStream = null;
bitmap = null;
}
}
最佳答案
这样试试
BitmapFactory.Options options=new BitmapFactory.Options();
options.inSampleSize=2; //decrease decoded image
Bitmap bitmap=BitmapFactory.decodeStream(is, null, options);
bitmap.compress(Bitmap.CompressFormat.JPEG, 70, fos);
关于Android - 在 BitmapFactory.decodeStream 返回之前调整图像大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25713829/