保存拍摄的图像在SD卡上的特定文件夹 [英] Save captured image in specific folder on sd card

查看:206
本文介绍了保存拍摄的图像在SD卡上的特定文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是在用相机在android系统工作,我是新来的Andr​​oid相机。我跟着从这里

I'm working with camera in android and I'm new to android camera. I've followed the tutorial from here

每当我将在Android清单添加外部存储权限,摄像头将其保存在默认目录不问我,我想将它保存在SD卡上创建了自己的文件夹中。我搜索了很多,但找不到任何有用的链接。请帮助,任何帮助将大大AP preciated。谢谢:)

Whenever I'll add External storage permission in android manifest, camera saves it in default directory without asking me and I want to save it in my own folder created in sd card. I'd searched a lot but couldn't find any useful link. Please help, any help will be much appreciated. Thank you :)

推荐答案

您可以添加的onActivityResult这code。这将您的图像存储一个名为YourFolderName文件夹中。

You can add this code in onActivityResult. This will store your image in a folder named "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();
    }

还需要设置权限的清单。

also need to set permission on Manifest

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

这篇关于保存拍摄的图像在SD卡上的特定文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆