首页 > 移动平台 > 详细

Android 读取本地(SD卡)图片

时间:2015-03-31 11:01:52      阅读:348      评论:0      收藏:0      [点我收藏+]
  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对象

Android 读取本地(SD卡)图片

原文:http://my.oschina.net/airship/blog/393868

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!