我有3个任务:
图像质量必须良好。
我的问题有解决办法吗?可能是一些图书馆?
答案 0 :(得分:3)
Android默认情况下实际上包含了您枚举的所有内容。
从图库中选择图片
Intent pickPhoto = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(pickPhoto, FROM_GALLERY);
从相机中捕捉图像
Intent takePicture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(takePicture, FROM_CAMERA);
要获取上述意图的结果并执行裁剪
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case FROM_GALLERY:
case FROM_CAMERA: {
if (resultCode == Activity.RESULT_OK) {
Uri selectedImage = data.getData();
Intent cropIntent = new Intent("com.android.camera.action.CROP");
cropIntent.setDataAndType(selectedImage, "image/*");
cropIntent.putExtra("crop", "true");
cropIntent.putExtra("aspectX", 1);
cropIntent.putExtra("aspectY", 1);
cropIntent.putExtra("outputX", MAX_WIDTH);
cropIntent.putExtra("outputY", MAX_HEIGHT);
cropIntent.putExtra("return-data", true);
startActivityForResult(cropIntent, PICTURE_CROP);
}
break;
}
case PICTURE_CROP: {
if (resultCode == Activity.RESULT_OK) {
final Bundle extras = data.getExtras();
if (extras != null) {
Bitmap photo = extras.getParcelable("data");
// Hurray! You now have the photo as a Bitmap
}
}
break;
}
}
}
更新
根据此post,您不应使用com.android.camera.action.CROP
,因为这并非在所有设备中都存在。在那篇文章中,他还列举了我将在此列出的备选方案: