2017-01-05 3 views
0

아래의 코드가 ucrop 라이브러리에서 사용되었으며 자르기 창이 나타납니다.Ucrop onActivityMethod가 작동하지 않습니다.

Uri destinationUri = Uri.fromFile(new File(myContext.getCacheDir(), "IMG_" + System.currentTimeMillis())); 
      UCrop.of(sourceUri, destinationUri) 
        .withMaxResultSize(maxWidth, maxHeight) 
        .start(myContext); 

그러나 컨트롤은 onActivityResult 메소드 내부에 없습니다./Else가 작동하지 않는 경우.

@Override 
public void onActivityResult(int requestCode, int resultCode, Intent data) { 
    if (resultCode == RESULT_OK && requestCode == UCrop.REQUEST_CROP) { 
     final Uri resultUri = UCrop.getOutput(data); 
    } else if (resultCode == UCrop.RESULT_ERROR) { 
     final Throwable cropError = UCrop.getError(data); 
    } 
} 

어떤 아이디어가 잘못 되었나요?

+0

자르려는 어떤 고정 된 비율은 있는가? ** 16 : 9, 4 : 3, 1 : 1 ** –

답변

0
Uri destinationUri = Uri.fromFile(new File(myContext.getCacheDir(), "IMG_" + System.currentTimeMillis())); 
       UCrop.of(sourceUri, destinationUri) 
       .withMaxResultSize(1080, 768) // any resolution you want 
       .start(mContext, YourFragment/YourActivity.this); 
+0

감사합니다. 나는 이미 대답을 찾았습니다 :-) – user7327850

+0

당신은 환영합니다, 친구! –

0

아래 코드로 변경하면 작동합니다.

Uri destinationUri = Uri.fromFile(new File(myContext.getCacheDir(), "IMG_" + System.currentTimeMillis())); 
    startActivityForResult(UCrop.of(sourceUri, destinationUri) 
      .withMaxResultSize(maxWidth, maxHeight) 
      .getIntent(getContext()),UCrop.REQUEST_CROP);