android中儲存圖片到/data/data//files/目錄中
阿新 • • 發佈:2019-02-10
public class SaveImageToRaw { private Context context; private Bitmap bitmap; public SaveImageToRaw(Context context){ this.context = context; } public void savaImage(String filename,Bitmap bitmap){ try { FileOutputStream fos = context.openFileOutput(filename,context.MODE_PRIVATE); //bitmap轉檔案物件 bitmap.compress(Bitmap.CompressFormat.PNG,100,fos); fos.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } public Bitmap getImage(String filename){ try { FileInputStream fis = context.openFileInput(filename); bitmap = BitmapFactory.decodeStream(fis); fis.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return bitmap; } }