1 byte[] bytes = decodeImagStr(imgString);//使用base64对图片进行解码
2 if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){//检查sd卡的状态
3 String pathDir= Environment.getExternalStorageDirectory()+ ConstantsForFile.TMP_FILE_DIRECTORY;//设定文件存放目录
4 String picName =new Date().getTime()+".jpg";
5 File dirFile = new File(pathDir);
6 if(!dirFile.exists())dirFile.mkdirs();//如果没有目录,则创建,mkDirs保证如果没有父目录时则创建父目录
7 File picFile = new File(pathDir,picName);//创建图片文件
8 FileOutputStream fileOutputStream = new FileOutputStream(picFile);//使用文件输出流
9 fileOutputStream.write(bytes);//输出文件
10 fileOutputStream.flush();
11 fileOutputStream.close();
12 return picFile.getPath();//返回图片路径
13 }