bitmap儲存到本地圖片的方法
阿新 • • 發佈:2018-12-12
/** * 儲存bitmap到本地 * * @param bitmap * @return */ public static void saveBitmap(Bitmap bitmap,int position) { String savePath; File filePic; if (Environment.getExternalStorageState().equals( Environment.MEDIA_MOUNTED)) { savePath = "/sdcard/dskqxt/pic/"; } else { Log.d("xxx", "saveBitmap: 1return"); return; } try { filePic = new File(savePath + position + ".jpg"); if (!filePic.exists()) { filePic.getParentFile().mkdirs(); filePic.createNewFile(); } FileOutputStream fos = new FileOutputStream(filePic); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos); fos.flush(); fos.close(); } catch (IOException e) { e.printStackTrace(); Log.d("xxx", "saveBitmap: 2return"); return; } Log.d("xxx", "saveBitmap: " + filePic.getAbsolutePath()); }