Android(安卓)读取本地(SD卡)图片
16lz
2022-04-20
[java] view plain copy
- private Bitmap getDiskBitmap(String pathString)
- {
- Bitmap bitmap = null;
- try
- {
- File file = new File(pathString);
- if(file.exists())
- {
- bitmap = BitmapFactory.decodeFile(pathString);
- }
- } catch (Exception e)
- {
- // TODO: handle exception
- }
- return bitmap;
- }
- private Bitmap getDiskBitmap(String pathString)
- {
- Bitmap bitmap = null;
- try
- {
- File file = new File(pathString);
- if(file.exists())
- {
- bitmap = BitmapFactory.decodeFile(pathString);
- }
- } catch (Exception e)
- {
- // TODO: handle exception
- }
- return bitmap;
- }
该方法实现了从本地路径读取一张图片, 可以是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读取服务器图片
- Android将Uri转化为文件路径的方法
- Android:JPEG EXIF信息添加
- Android(安卓)SharedPreferences使用
- 安卓各文件存储路径汇总(Android(安卓)file path)
- android过滤隐藏文件FileFilter
- Android(安卓)把Layout变成图片
- android中读取短信
- Android之录音工具类