1
我试图调整从SD卡中选择一个缩略图大小的图片,但是当我调整它的大小,在尺寸上我的默认图像128/128
位图是空位图图像为null调整后
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
做呢?
啊不知道的是,这是原因 – tyczj 2012-07-31 00:36:00