android 通過uri獲取圖片並根據限制大小讀取圖片的方法
阿新 • • 發佈:2019-02-03
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();}