Android 图像系列: 将本地图片加载到Drawable
/** * 将文件生成位图 * @param path * @return * @throws IOException */public BitmapDrawable getImageDrawable(String path)throws IOException{//打开文件File file = new File(path);if(!file.exists()){return null;}ByteArrayOutputStream outStream = new ByteArrayOutputStream();byte[] bt = new byte[BUFFER_SIZE];//得到文件的输入流InputStream in = new FileInputStream(file);//将文件读出到输出流中int readLength = in.read(bt);while (readLength != -1) {outStream.write(bt, 0, readLength);readLength = in.read(bt);}//转换成byte 后 再格式化成位图byte[] data = outStream.toByteArray();Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);// 生成位图BitmapDrawable bd = new BitmapDrawable(bitmap);return bd;}