1. 程式人生 > >android 通過uri獲取圖片並根據限制大小讀取圖片的方法

android 通過uri獲取圖片並根據限制大小讀取圖片的方法

uri = data.getData();BitmapFactory.Options options =newBitmapFactory.Options();
                options.inJustDecodeBounds =true;try{BitmapFactory.decodeStream(getContentResolver().openInputStream(uri),null, options);
                    options.inSampleSize = calculateInSampleSize(options,100,100);
                    options
.inJustDecodeBounds =false;Bitmap image =BitmapFactory.decodeStream(getContentResolver().openInputStream(uri),null, options); imageofpic.setImageBitmap(image);}catch(FileNotFoundException e){ e.printStackTrace();}