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

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

问题描述

嘿,我是新来的Andr​​oid和我一直在试图让一个应用程序最近。基本上,我想要做的就是让用户来做出自己的文件夹,然后转到包含一个按钮,启动摄像头的活动。从那里,我希望能够启动摄像头并保存摄像机的图像到新创建的文件夹中。我有保存照相机图像到新创建的文件夹中的最后一部分麻烦。

Hey I'm new to Android and I have been trying to make an app recently. 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. From there I want to be able to launch the camera and save the camera images into the newly created folder. 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);
        }
    });         
    }
}

请告诉我如何从相机中的图像保存到新创建的文件夹中。我希望用户能够采取一些照片,然后保存这些多张图片到该特定的文件夹。在此先感谢!

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. Thanks in advance!

推荐答案

呼叫相机活动之前添加此code,

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天全站免登陆