[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. 直播源码用Glide框架缓存压缩图片做一个网络图片查看器
  2. Android将Uri转化为文件路径的方法
  3. Android图片解决方案
  4. Android 圆角图片 圆形图片
  5. android 调用相册里的图片并返回
  6. Android 图片透明度处理代码
  7. Android读取服务器图片

随机推荐

  1. golang 协程占多大内存
  2. golang 指针怎么用
  3. golang 为什么没有枚举
  4. golang 怎么做热更新
  5. GOLANG 为什么还有指针
  6. golang 怎么调用c代码
  7. golang 数组存的是什么
  8. golang 怎么设计一个栈
  9. golang 是面向对象的么
  10. golang 怎么拼接字符串