默认的摄像头采取的android图片 [英] default camera to take a picture in android

查看:131
本文介绍了默认的摄像头采取的android图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用默认的摄像头拍摄照片的机器人?

解决方案

 乌里imageUri;
最终诠释TAKE_PICTURE = 115;

公共无效capturePhoto(查看视图){
    意向意图=新的意图(android.media.action.IMAGE_CAPTURE);
    文件photoFile =新的文件(Environment.getExternalStorageDirectory(),Photo.png);
    intent.putExtra(MediaStore.EXTRA_OUTPUT,
            Uri.fromFile(photoFile));
    imageUri = Uri.fromFile(photoFile);
    startActivityForResult(意向,TAKE_PICTURE);
}

@覆盖
公共无效onActivityResult(INT申请code,INT结果code,意图数据){
    super.onActivityResult(要求code,因此code,数据);
    开关(要求code){
        案例TAKE_PICTURE:
            如果(结果code == Activity.RESULT_OK){
                乌里selectedImageUri = imageUri;
                //做你想做的
        }
    }
}
 

How to use default camera to take a picture in android ?

解决方案

Uri imageUri;
final int TAKE_PICTURE = 115;

public void capturePhoto(View view) {
    Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
    File photoFile = new File(Environment.getExternalStorageDirectory(),  "Photo.png");
    intent.putExtra(MediaStore.EXTRA_OUTPUT,
            Uri.fromFile(photoFile));
    imageUri = Uri.fromFile(photoFile);
    startActivityForResult(intent, TAKE_PICTURE);
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {
        case TAKE_PICTURE:
            if (resultCode == Activity.RESULT_OK) {
                Uri selectedImageUri = imageUri;
                //Do what ever you want
        }
    }
}

这篇关于默认的摄像头采取的android图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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