0

我在使用 Android Studio 的照片编辑器应用程序中使用DsPhotoEditorSDK。但是编辑后我对 ResultActivity 有问题。图片无法在 ResultActivity 中加载。如果有人已经遇到过这个问题,知道原因,或者如何解决。请帮我 ;-;

这是我的主要活动

public class MainActivity extends AppCompatActivity {

ActivityMainBinding binding;
int IMAGE_REQUEST_CODE = 45;
int CAMERA_REQUEST_CODE = 14;
int RESULT_CODE = 200;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    binding = ActivityMainBinding.inflate(getLayoutInflater());
    setContentView(binding.getRoot());

    binding.gearView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(MainActivity.this, ResultActivity.class);
            startActivity(intent);
        }
    });

    binding.editBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_GET_CONTENT);
            intent.setType("image/*");
            startActivityForResult(intent, IMAGE_REQUEST_CODE);
        }
    });

    binding.cameraBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (ActivityCompat.checkSelfPermission(MainActivity.this,
                    Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
                ActivityCompat.requestPermissions(MainActivity.this,
                        new String[] {Manifest.permission.CAMERA}, 32);
            } else {
                Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                startActivityForResult(cameraIntent, CAMERA_REQUEST_CODE);
            }
        }
    });

}

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == IMAGE_REQUEST_CODE) {
        if (data.getData() != null) {
            Uri filePath = data.getData();
            Intent dsPhotoEditorIntent = new Intent(this, DsPhotoEditorActivity.class);
            dsPhotoEditorIntent.setData(filePath);
            dsPhotoEditorIntent.putExtra(DsPhotoEditorConstants.DS_PHOTO_EDITOR_OUTPUT_DIRECTORY, "CitraDigital");
            int[] toolsToHide = {DsPhotoEditorActivity.TOOL_ORIENTATION, DsPhotoEditorActivity.TOOL_CROP};
            dsPhotoEditorIntent.putExtra(DsPhotoEditorConstants.DS_PHOTO_EDITOR_TOOLS_TO_HIDE, toolsToHide);
            startActivityForResult(dsPhotoEditorIntent, RESULT_CODE);
        }
    }

    if (requestCode == CAMERA_REQUEST_CODE) {
        Bitmap photo = (Bitmap) data.getExtras().get("data");
        Uri uri = getImageUri(photo);
        Intent dsPhotoEditorIntent = new Intent(this, DsPhotoEditorActivity.class);
        dsPhotoEditorIntent.setData(uri);
        dsPhotoEditorIntent.putExtra(DsPhotoEditorConstants.DS_PHOTO_EDITOR_OUTPUT_DIRECTORY, "CitraDigital");
        int[] toolsToHide = {DsPhotoEditorActivity.TOOL_ORIENTATION, DsPhotoEditorActivity.TOOL_CROP};
        dsPhotoEditorIntent.putExtra(DsPhotoEditorConstants.DS_PHOTO_EDITOR_TOOLS_TO_HIDE, toolsToHide);
        startActivityForResult(dsPhotoEditorIntent, RESULT_CODE);
    }

    if (requestCode == RESULT_CODE) {
        Intent intent = new Intent(MainActivity.this, ResultActivity.class);
        intent.setData(data.getData());
        startActivity(intent);
    }
}

public Uri getImageUri(Bitmap bitmap) {
    ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, arrayOutputStream);
    String path = MediaStore.Images.Media.insertImage(getContentResolver(), bitmap, "Title",  null);
    return Uri.parse(path);
}

这是我的 ResultActivity

 ActivityResultBinding binding;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    binding = ActivityResultBinding.inflate(getLayoutInflater());
    setContentView(binding.getRoot());

    binding.image.setImageURI(getIntent().getData());
4

0 回答 0