2

アクティビティ結果で画像をトリミングするときに問題があります。デバイス > 6 に権限を設定しました。ただし、show crop と crop が成功すると、結果データは null になります。( imageReturnedIntent.getData()us null であり、インテント データも null です)。コードクロップ画像です。

public static Intent cropIntent(Uri inUri, int outputX, int outputY,
                                    boolean isScale) {
    Intent cropIntent = new Intent("com.android.camera.action.CROP");
    cropIntent.setDataAndType(inUri, "image/*");
    cropIntent.putExtra("crop", "true");
    cropIntent.putExtra("aspectX", outputX > 0 ? outputX : 100);
    cropIntent.putExtra("aspectY", outputY > 0 ? outputY : 100);
    cropIntent.putExtra("outputX", outputX > 0 ? outputX : 100);
    cropIntent.putExtra("outputY", outputY > 0 ? outputY : 100);
    cropIntent.putExtra("scale", isScale);
    File file = new File(Environment.getExternalStorageDirectory() + File.separator + "img.jpg");
    Uri mCropImagedUri = Uri.fromFile(file);
    cropIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, mCropImagedUri);
    cropIntent.putExtra("return-data", true);
    return cropIntent;
}

コード活動ですsult

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
    super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
    if (callbackManager != null) {
        callbackManager.onActivityResult(requestCode, resultCode, imageReturnedIntent);

    }

    switch (requestCode) {
        case SELECT_PHOTO:
            if (resultCode == RESULT_OK) {

                Uri uriImage = imageReturnedIntent.getData();
                System.out.println(">>>> uri "+uriImage);
                //   CommonUtils.cropImage(uriImage,HomeActivity.this,SELECT_CROP_IMAGE);
                startActivityForResult(CommonUtils.cropIntent(uriImage,
                        200, 200, true), SELECT_CROP_IMAGE);
            }
            break;
        case SELECT_CROP_IMAGE:
            if (resultCode == RESULT_OK) {
                //   Uri uri = imageReturnedIntent.getData();

                System.out.println(">>>>> "+imageReturnedIntent.getData());
                Bundle extras = imageReturnedIntent.getExtras();
                if (extras == null) {
                    System.out.println(">>>>> check intent");
                    return;
                }
                // Bitmap bitMapScale = extras.getParcelable("data");
                Uri uri = extras.getParcelable(MediaStore.EXTRA_OUTPUT);
                try {
                    Bitmap bitMapScale = MediaStore.Images.Media.getBitmap(this.getContentResolver(), uri);
                    System.out.println(">>>>>> check " + bitMapScale);
                    //       yourSelectedImage.recycle();
                    // base64
                    String myBase64Image = CommonUtils.encodeToBase64(bitMapScale, Bitmap.CompressFormat.PNG, 100);
                    //   bitMapScale.recycle();
                    assert uri != null;
                    LocalStorage.getShareInstance().saveUriAvatar(uri.toString());
                    LocalStorage.getShareInstance().saveBase64Image(myBase64Image);
                    UserModel userModel = LocalStorage.getShareInstance().getUserLogin();
                    if (userModel == null) {
                        // if user have not login.
                        if (uiLeftMenu != null) {
                            uiLeftMenu.fillImage(uri);
                        }
                    } else {
                        System.out.println(">>>>>> check data");
                        if (CommonUtils.isStringDataValid(myBase64Image)) {

                            upLoadImageToServerWithStringBase64(myBase64Image);
                        }
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }


            }
            break;
    }
}

何が問題ですか?

4

1 に答える 1