Android 调整大小后位图图像为空
我正试图将从SD卡中选择的图片调整为缩略图大小,但当我将其调整为默认图像上的尺寸时,Android 调整大小后位图图像为空,android,bitmap,Android,Bitmap,我正试图将从SD卡中选择的图片调整为缩略图大小,但当我将其调整为默认图像上的尺寸时,128/128位图为空 InputStream input=null; try { input = getActivity().getContentResolver().openInputStream(Uri.parse(cursor.getString(3))); BitmapFactory.Options options
128/128
位图为空
InputStream input=null;
try {
input = getActivity().getContentResolver().openInputStream(Uri.parse(cursor.getString(3)));
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeStream(input, null, options);
int height = options.outHeight; //1030
int width = options.outWidth; //1033
BitmapFactory.decodeResource(getResources(), R.drawable.ic_contact_picture, options);
int imageHeight = options.outHeight; //128
int imageWidth = options.outWidth; //128
if(imageWidth > imageHeight){
options.inSampleSize = Math.round((float)height/(float)imageHeight);
}else{
options.inSampleSize = Math.round((float)width/(float)imageWidth);
}
options.inJustDecodeBounds = false;
Bitmap bm = BitmapFactory.decodeStream(input,null, options); //null here
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
image.setImageBitmap(bm);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
我可以得到两个图像的高度和宽度,但当我去调整它的大小,它返回一个空位图
我用资源文件这样做过,但从未用SD卡图像的
Uri
这样做过,那么我做错了什么呢?同一个输入流不能使用两次,所以第二次需要创建一个新的输入流。有关更多信息,请参阅。ahh不知道,这就是原因