赞
踩
调用系统图库并返回图片的url:
- Intent intentFromGallery = new Intent();
- intentFromGallery.setType("image/*"); // 设置文件类型
- intentFromGallery.setAction(Intent.ACTION_PICK);
- startActivityForResult(intentFromGallery, IMAGE_REQUEST_CODE);
- // 判断存储卡是否可以用,可用进行存储
- if (Tools.hasSdcard()) {
- Intent intentFromCapture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
- File file = new File(Environment.getExternalStorageDirectory(), IMAGE_FILE_NAME);
- intentFromCapture.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
- startActivityForResult(intentFromCapture,CAMERA_REQUEST_CODE);
- }
- Intent intent = new Intent("com.android.camera.action.CROP");
- intent.setDataAndType(uri, "image/*");
- // 设置裁剪
- intent.putExtra("crop", "true");
- // aspectX aspectY 是宽高的比例
- intent.putExtra("aspectX", 1);
- intent.putExtra("aspectY", 1);
- // outputX outputY 是裁剪图片宽高
- intent.putExtra("outputX", 320);
- intent.putExtra("outputY", 320);
- intent.putExtra("return-data", true);
- startActivityForResult(intent, 2);
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。