- 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对象
- 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对象
本文介绍了一种通过Java实现的从本地路径加载图片的方法。该方法可以读取多种格式的图片,例如jpg、bmp和png等,并使用BitmapFactory进行解码。

2万+

被折叠的 条评论
为什么被折叠?



