标签:android io java ar for 文件 art div cti
private static final int TAKE_PICTURE_FROM_ALBUM = 1; private void takePictureFromAlbum() { Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("image/*"); startActivityForResult(intent, TAKE_PICTURE_FROM_ALBUM); }2. 通过startAcitivityForResult()方法,我们可以在onAcitivityResult()中来获取图片的URI,然后将图片的URI传递给图片裁剪函数,代码如下:
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == Activity.RESULT_OK) { switch (requestCode) { case TAKE_PICTURE_FROM_ALBUM: if (data != null) { cropPictureFromAlbum(data.getData()); } break; case PICTURE_CROP_CODE: if (data != null) { // 这是裁剪后图片的bitmap Bitmap bitmap = data.getParcelableExtra("data"); } break; default: break; } } } private static final int TAKE_PICTURE_FROM_ALBUM = 1; private void takePictureFromAlbum() { Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("image/*"); startActivityForResult(intent, TAKE_PICTURE_FROM_ALBUM); } private static final int PICTURE_CROP_CODE = 2; private void cropPictureFromAlbum(Uri pictureUri) { Intent intent = new Intent("com.android.camera.action.CROP"); intent.setDataAndType(pictureUri, "image/*"); intent.putExtra("crop", "true"); // 裁剪框比例 intent.putExtra("aspectX", 1); intent.putExtra("aspectY", 2); // 裁剪后输入图片的尺寸大小 intent.putExtra("outputX", 300); intent.putExtra("outputY", 300); // 取消人脸识别 intent.putExtra("noFaceDetection", true); intent.putExtra("return-data", true); startActivityForResult(intent, PICTURE_CROP_CODE); }
标签:android io java ar for 文件 art div cti
原文地址:http://blog.csdn.net/wzy_1988/article/details/38942525