我创建了一个图像FileOutputStream
,我尝试将其保存到图库。我一直在寻找堆栈溢出的答案以及其他所有内容,但对我来说却无济于事
我的代码:
File path = MainActivity.this.getExternalFilesDir("ComputerScreenshots");
FileOutputStream ops = new FileOutputStream(path + "/Computer.png");
上面的代码将图像保存在 /storage/emulated/0/Android/data/com.example.computer/files/ComputerScreenshots/Computer.png
如何将其保存到图库?
我认为以下代码将为您提供帮助。
File path = new File( Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_DCIM), "ComputerScreenshots");
检查您的目录是否存在?如果没有,那就去做。
if (!path.exists())
path.mkdir()
如果要将图像保存到相机目录中,则将ComputerScreenshots替换为Camera
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句