码迷,mamicode.com
首页 > 移动开发 > 详细

Android 应用拍照

时间:2015-05-27 17:25:07      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:android   camera   

  • 申请权限
 <uses-feature android:name="android.hardware.camera"
                  android:required="true" />
  • 检查相机是否可以使用
hasSystemFeature(PackageManager.FEATURE_CAMERA). 
  • 获取照片
static final int REQUEST_IMAGE_CAPTURE = 1;

private void dispatchTakePictureIntent() {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
        startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
    }
}
  • 获取照片缩略图
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
        Bundle extras = data.getExtras();
        Bitmap imageBitmap = (Bitmap) extras.get("data");
        mImageView.setImageBitmap(imageBitmap);
    }
}

Android 应用拍照

标签:android   camera   

原文地址:http://blog.csdn.net/xiangaaa190/article/details/46048147

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!