1. 程式人生 > >征服SD卡儲存及獲取圖片

征服SD卡儲存及獲取圖片

private void saveBitmapToSD(Bitmap bitmap,String bitName) throws IOException    {       Environment.getExternalStorageDirectory();       File file = new File( getContext().getFilesDir()+File.separator+ bitName);       if(!file.exists()){ //       file.delete(); boolean result = file.createNewFile();       }       FileOutputStream out;       try
{          out = new FileOutputStream(file);          if(bitmap.compress(Bitmap.CompressFormat.PNG, 90, out))          {             out.flush();             out.close();          }       }       catch (FileNotFoundException e)       {          e.printStackTrace();       }       catch (IOException e)       {          e.printStackTrace();       }    }    private
Bitmap getBitmapInSD(String imgName) {       Bitmap bitmap = null;       String pathString=getContext().getFilesDir()+File.separator + imgName;       try {          // File file = new File(pathString);          // if (file.exists()) { bitmap = BitmapFactory.decodeFile(pathString);          // } } catch
(Exception e) {       }       return bitmap;    }