我想将图像视图保存到特定文件夹中的图像,我尝试了这段代码,但它不起作用
public void saveImage(View v){
View content = findViewById(R.id.iv_photo);
content.setDrawingCacheEnabled(true);
Bitmap bitmap = content.getDrawingCache();
//File file = new File("/DCIM/Camera/image.jpg");
File root = Environment.getExternalStorageDirectory();
File file = new File(root.getAbsolutePath() + "/DCIM/image.jpg");
try {
file.createNewFile();
FileOutputStream ostream = new FileOutputStream(file);
bitmap.compress(CompressFormat.JPEG, 100, ostream);
ostream.close();
}catch (Exception e){
e.printStackTrace();
}
}
以及调用函数的这段代码
saveImage(getWindow().getDecorView().findViewById(android.R.id.content));