gpt4 book ai didi

android - 将捕获的图像保存在 SD 卡上的特定文件夹中

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:59:22 25 4
gpt4 key购买 nike

我在 android 中使用相机,我是 android 相机的新手。我已按照 here 中的教程进行操作

每当我在 android list 中添加外部存储权限时,相机会在不询问我的情况下将其保存在默认目录中,我想将其保存在我自己在 sd 卡中创建的文件夹中。我搜索了很多但找不到任何有用的链接。请帮助,任何帮助将不胜感激。谢谢:)

最佳答案

您可以在 onActivityResult 中添加此代码。这会将您的图像存储在名为“YourFolderName”的文件夹中

String extr = Environment.getExternalStorageDirectory().toString()
+ File.separator + "YourFolderName";
File myPath = new File(extr, fileName);
FileOutputStream fos = null;
try {
fos = new FileOutputStream(myPath);
bitMap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.flush();
fos.close();
MediaStore.Images.Media.insertImage(context.getContentResolver(),
bitMap, myPath.getPath(), fileName);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

还需要对Manifest设置权限

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

关于android - 将捕获的图像保存在 SD 卡上的特定文件夹中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25241960/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com