갤러리 나 카메라에서 이미지를 가져온 후 이미지를 자르려는 문제가 있습니다.카메라에서 사진을 찍은 후 갤러리 화면을 표시 안 함 Android
갤러리에서 이미지를 선택하면 문제없이 올바르게 잘립니다. 카메라에서 이미지를 선택하면 자르기가 제대로 끝났지 만 자르기 화면으로 바로 이동하지 않고 아래에 표시된 "중간"화면을 보여줍니다.
참고 : 그림은 위의 표현 목적은 "중간"최근 화면을 표시하는 단지입니다.
"중간"최근 화면을 표시하고 싶지 않습니다. 대신 직접 작물 의도를 탐색하려고합니다. Whatsapp과 같은 앱에서 누군가가 프로필 사진을 변경하면이 동작이 표시되지 않습니다. "중간"화면을 표시하지 않고 자르기 의도로 직접 이동합니다.
누군가가이 문제를 해결할 수 있습니까?
여기 내 전체 코드
/**
* This activity is used to display profile picture and update the same
*
*/
public class ChangeProfilePhotoActivity extends BaseActivity implements
View.OnClickListener {
private TextView mTvTitle;
private ImageView mBtnChangePhoto;
private ImageView mIvProfileImage;
public static final int CROP_PIC_REQUEST_CODE = 3;
public static final int TAKE_PICTURE = 1;
public static final int GALLERY_IMAGE = 2;
public static final int IMAGE_CHOOSER_INTENT = 4;
int PERMISSION_ALL = 10;
String[] PERMISSIONS = { Manifest.permission.CAMERA};
//private Uri mImageUri;
//private Uri mCropImageUri;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile_photo);
initUI();
}
@Override
protected void onResume() {
super.onResume();
}
@Override
protected void onPause() {
super.onPause();
}
@Override
protected void onDestroy() {
super.onDestroy();
}
private void initUI() {
mBtnChangePhoto = (ImageView) findViewById(R.id.btnChangePhoto);
mIvProfileImage = (ImageView) findViewById(R.id.profile_image);
mBtnChangePhoto.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnChangePhoto:
//launch intent chooser
getPickImageIntent(this);
break;
default:
break;
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
try {
if (resultCode == Activity.RESULT_OK) {
switch (requestCode) {
case IMAGE_CHOOSER_INTENT:
if(data!=null){
String action = data.getAction();
Uri selectedImageUri = data.getData();
//send image for cropping
doCrop(selectedImageUri);
}
break;
case CROP_PIC_REQUEST_CODE:
if(data!=null){
Bundle extras = data.getExtras();
if(extras != null) {
Bitmap bmp = (Bitmap) extras.get("data");
mIvProfileImage.setImageBitmap(bmp);
}
}
break;
default:
break;
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
private void doCrop(Uri picUri) {
try {
Intent cropIntent = new Intent("com.android.camera.action.CROP");
cropIntent.setDataAndType(picUri, "image/*");
cropIntent.putExtra("crop", "true");
cropIntent.putExtra("aspectX", 1);
cropIntent.putExtra("aspectY", 1);
cropIntent.putExtra("outputX", 128);
cropIntent.putExtra("outputY", 128);
cropIntent.putExtra("return-data", true);
startActivityForResult(cropIntent, CROP_PIC_REQUEST_CODE);
}
// respond to users whose devices do not support the crop action
catch (ActivityNotFoundException anfe) {
// display an error message
String errorMessage = "Your device doesn't support the crop action!";
Toast toast = Toast.makeText(this, errorMessage, Toast.LENGTH_SHORT);
toast.show();
}
}
public void getPickImageIntent(Context context) {
Intent chooserIntent = null;
List<Intent> intentList = new ArrayList<>();
Intent pickIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
//startActivityForResult(pickIntent, GALLERY_IMAGE);
Intent takePhotoIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
/* String imageFilePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/crop_image.jpg";
File imageFile = new File(imageFilePath);
Uri picUri = Uri.fromFile(imageFile); // convert path to Uri
takePhotoIntent.putExtra(MediaStore.EXTRA_OUTPUT, picUri);*/
//takePhotoIntent.putExtra("return-data", false);
//startActivityForResult(takePhotoIntent, TAKE_PICTURE);
intentList = addIntentsToList(context, intentList, pickIntent);
intentList = addIntentsToList(context, intentList, takePhotoIntent);
if (intentList.size() > 0) {
chooserIntent = Intent.createChooser(intentList.remove(intentList.size() - 1),
context.getString(R.string.pick_image_intent_text));
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentList.toArray(new Parcelable[intentList.size()]));
}
startActivityForResult(chooserIntent, IMAGE_CHOOSER_INTENT);
}
private static List<Intent> addIntentsToList(Context context, List<Intent> list, Intent intent) {
try {
List<ResolveInfo> resInfo = context.getPackageManager().queryIntentActivities(intent, 0);
for (ResolveInfo resolveInfo : resInfo) {
String packageName = resolveInfo.activityInfo.packageName;
Intent targetedIntent = new Intent(intent);
targetedIntent.setPackage(packageName);
list.add(targetedIntent);
}
} catch (Exception ex) {
ex.printStackTrace();
}
return list;
}
}
[Android에는'CROP'' Intent']이 없습니다 (https://commonsware.com/blog/2013/01/23/no-android-does-not-have-crop-intent.html). 많은 [안드로이드에서 사용할 수있는 이미지 자르기 라이브러리] (https://android-arsenal.com/tag/45)가 있습니다. 하나를 사용하십시오. 부작용으로 장치가 CROP 활동을하지 않거나 기대하지 않는 활동으로 인해 앱 충돌에 대해 더 이상 걱정할 필요가 없습니다. – CommonsWare
좋아요. 케이스가 아니라면 의도가 아니라 라이브러리로 갈 것입니다. –