本文實例講述了Android編程實現讀取本地SD卡圖片的方法。分享給大家供大家參考,具體如下:
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);}
讀取到本地文件后, 先判斷一下是否存在該文件。
希望本文所述對大家Android程序設計有所幫助。
新聞熱點
疑難解答
圖片精選