標籤:false null 圖片 file
1. 儲存到自訂路徑
Calendar name = Calendar.getInstance();String path = "/sdcard/lef/";if (Environment.getExternalStorageDirectory() != null) {File file = new File(path);if (!file.exists())file.mkdirs();dv.setDrawingCacheEnabled(true);Bitmap a = Bitmap.createBitmap(dv.getDrawingCache());dv.setDrawingCacheEnabled(false);FileOutputStream fo = new FileOutputStream(file.getPath()+ "/" + name.getTimeInMillis() + ".png");a.compress(Bitmap.CompressFormat.PNG, 100, fo);fo.flush();fo.close();}sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,Uri.parse("file://"+ Environment.getExternalStorageState() + path)));Toast.makeText(HandDraw.this, "圖片儲存成功", Toast.LENGTH_SHORT).show();2.儲存到系統相簿 ContentResolver cr = HandDraw.this.getContentResolver();String path = MediaStore.Images.Media.insertImage(cr ,Bitmap.createBitmap(dv.cacheBitmap), "", ""); sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://"+ Environment.getExternalStorageDirectory()+ path)));