SD卡写入图片

2019-04-15 14:39发布

public void saveImg(View view){ BitmapDrawable bitmapDrawable= (BitmapDrawable) img.getDrawable(); Bitmap bitmap= bitmapDrawable.getBitmap(); //拿到图片 File file=Environment.getExternalStorageDirectory(); FileOutputStream fos= null; try { fos = new FileOutputStream(file+"/1.png"); bitmap.compress(Bitmap.CompressFormat.PNG,100,fos); } catch (FileNotFoundException e) { e.printStackTrace(); }finally { if(fos!=null){ try { fos.close(); } catch (IOException e) { e.printStackTrace(); } } } }