android照片相機拍照和本地照片選擇會出現問題。
對於本地照片選擇,android 4.0和android4.4路徑選擇不同
4.4獲取圖片方式:Uri selectedImage = data.getData();
String imagePath = ImageTools.getPath(this, selectedImage); // 獲取圖片的絕對路徑
newUri = Uri.parse("file:///" + imagePath); // 將絕對路徑轉換爲URL
4.0獲取newUri = data.getData();
獲取到的圖片之後,我們一般是用photo = BitmapFactory.decodeStream(getContentResolver().openInputStream(uri));來獲取圖片
但是測試了所有之後,小米手機卻報了內存溢出,這裏我們要加一下改變
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Config.RGB_565;
bitmap=BitmapFactory.decodeStream(getContentResolver().openInputStream(newUri),null,options);
這樣就解決了oom問題了。