android 照片拍照問題

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問題了。

 

 

 

 

發佈了33 篇原創文章 · 獲贊 6 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章