如何将Android相机中的图像保存到特定文件夹? [英] How to save images from Camera in Android to specific folder?

查看:65
本文介绍了如何将Android相机中的图像保存到特定文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我想做的是允许用户制作自己的 folder,然后转到包含 buttonactivity启动相机.

Basically, what I want to do is allow the user to make their own folder and then go to an activity that contains a button to launch the camera.

从那里我希望能够启动 camera 并将 camera 图像保存到新创建的文件夹中.

From there I want to be able to launch the camera and save the camera images into the newly created folder.

我在将 camera 图像保存到新创建的文件夹的最后部分遇到问题.

I am having trouble with last part of saving the camera images into the newly created folder.

这是我的代码:

 public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Button b = (Button) findViewById(R.id.button1);
    b.setOnClickListener(new OnClickListener() {


        EditText text = (EditText)findViewById(R.id.editText1); 
        EditText text2 = (EditText)findViewById(R.id.editText2);



        @Override
        public void onClick(View v) {

            final String name = text.getText().toString();
            final String placeName = text2.getText().toString(); 

            String place = placeName.substring(0,3);
            String direct = name + place ;

            File folder = new File("/sdcard/CameraTest/" + direct + "/");
            folder.mkdirs();

            Intent myIntent = new Intent(CameraTestActivity.this, Press.class);
            myIntent.putExtra("key", "/sdcard/CameraTest/" + direct + "/");
            startActivity(myIntent);

        }
    });

从这里我过渡到这个活动:

From here I transition into this activity:

public class Press extends Activity {


    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.afterenter);
        final String direct = this.getIntent().getStringExtra("key");


        // TODO Auto-generated method stub
        Button p = (Button) findViewById(R.id.button2);
        p.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                Intent camera= new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);

                startActivityForResult(camera, 1);

            }
        });



    Button np = (Button) findViewById(R.id.button3);
    np.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent next = new Intent(Press.this, CameraTestActivity.class);
            startActivity(next);
        }
    });         
    }
}

请告诉我如何将 camera 中的图像保存到新创建的文件夹中.

Please tell me how to save the images from the camera into the newly created folder.

我希望用户能够拍摄几张图片,然后将这几张图片保存到该特定文件夹中.

I want the user to be able to take several pictures and then save these several pictures into that specific folder.

推荐答案

在调用camera activity之前添加这段代码,

add this code before calling camera activity,

Uri uriSavedImage=Uri.fromFile(new File("/sdcard/flashCropped.png"));
camera.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
startActivityForResult(camera, 1);

这篇关于如何将Android相机中的图像保存到特定文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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