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万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章