调用系统图库并返回图片的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);

}

获取回传的图片url,调用系统编辑图片的功能:

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);

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐