如何启动相机和拍照 [英] How to launch the camera and take a picture

查看:160
本文介绍了如何启动相机和拍照的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让一个机器人演示。在演示中,我必须拿出相机的活动,并推进到另一个活动,我可以看到摄像头的画面和一个小菜单前拍照。

I'm trying to make an Android demo. In the demo, I have to show the camera in an activity and take a picture before advancing to another activity where I can see the camera with the picture and a little menu.

我如何可以启动相机和拍照?

How can I launch the camera and take a picture?

推荐答案

在我的应用我用下面的code来启动相机:

In my app I use the following code to Launch the camera:

public void imageFromCamera() {
    Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
    mImageFile = new File(Environment.getExternalStorageDirectory()+File.separator+"MyApp",  
            "PIC"+System.currentTimeMillis()+".jpg");
    mSelectedImagePath = mImageFile.getAbsolutePath();
    intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mImageFile));
    startActivityForResult(intent, TAKE_PICTURE);
}

这将图像保存到该路径mSelectedImagePath这是/sdcard/MyApp/.jpg。

This will save the image to the path mSelectedImagePath which is /sdcard/MyApp/.jpg.

然后你捕捉IMAGE_CAPTURE意图在onActivityResult的回报并启动活动,从那里编辑的图像!

Then you capture the return of the IMAGE_CAPTURE intent in onActivityResult and launch your activity to edit the image from there!

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_OK) {
        switch(requestCode) {
        case TAKE_PICTURE:
                    //Launch ImageEdit Activity
            Intent i = new Intent(this, ImageEdit.class);
                    i.putString("imgPath", "mSelectedImagePath");
                    startActivity(i);
            break;
        }
    }
}

希望这有助于!

Hope this helps!

这篇关于如何启动相机和拍照的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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