[java] view plain copy
  1. private Bitmap getDiskBitmap(String pathString)  
  2. {  
  3.     Bitmap bitmap = null;  
  4.     try  
  5.     {  
  6.         File file = new File(pathString);  
  7.         if(file.exists())  
  8.         {  
  9.             bitmap = BitmapFactory.decodeFile(pathString);  
  10.         }  
  11.     } catch (Exception e)  
  12.     {  
  13.         // TODO: handle exception  
  14.     }  
  15.       
  16.       
  17.     return bitmap;  
  18. }  
[java] view plain copy
  1. private Bitmap getDiskBitmap(String pathString)  
  2. {  
  3.     Bitmap bitmap = null;  
  4.     try  
  5.     {  
  6.         File file = new File(pathString);  
  7.         if(file.exists())  
  8.         {  
  9.             bitmap = BitmapFactory.decodeFile(pathString);  
  10.         }  
  11.     } catch (Exception e)  
  12.     {  
  13.         // TODO: handle exception  
  14.     }  
  15.       
  16.       
  17.     return bitmap;  
  18. }  

 

该方法实现了从本地路径读取一张图片, 可以是jpg、bmp、png等多种格式。

pathString 是本地图片路径   如: "mnt/sdcard/1.jpg"

 

File file = new File(pathString);

if(file.exists())

{bitmap = BitmapFactory.decodeFile(pathString);}

 

读取到本地文件后, 先判断一下是否存在该文件。

BitmapFactory.decodeFile(pathString);

对本地文件进行解码, 可以是多种图片格式。 返回BITMAP对象


更多相关文章

  1. Android读取服务器图片
  2. Android将Uri转化为文件路径的方法
  3. Android:JPEG EXIF信息添加
  4. Android(安卓)SharedPreferences使用
  5. 安卓各文件存储路径汇总(Android(安卓)file path)
  6. android过滤隐藏文件FileFilter
  7. Android(安卓)把Layout变成图片
  8. android中读取短信
  9. Android之录音工具类

随机推荐

  1. Python---列表生成式
  2. python全栈学习--day31(正则)
  3. python函数的属性
  4. Django 连接 Mysql (8.0.16) 失败
  5. python_列表_循环遍历
  6. 应用Python开发WebService服务端及客户端
  7. 【Python】logging结合decorator模式实优
  8. python接入微博第三方API之2接入用户登录
  9. Python开发利器——wingIDE破解技巧
  10. python subprocess模块 监控子进程的2种