Crop an image when selected from gallery in android

后端 未结 6 555
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-02 08:51

I want to crop an image in my application when it is selected from gallery. i.e if I launch the gallery and select an image the cropping window should come like when we sele

6条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-02 09:09

    I solved this problem this way

    private void pickUserImage() { 
    
    if (doHavePermission()) { 
        Intent photoPickerIntent = new Intent(Intent.ACTION_PICK,
                android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
        photoPickerIntent.setType("image/*");
        photoPickerIntent.putExtra("crop", "true");
        photoPickerIntent.putExtra("scale", true);
        photoPickerIntent.putExtra("outputX", 256);
        photoPickerIntent.putExtra("outputY", 256);
        photoPickerIntent.putExtra("aspectX", 1);
        photoPickerIntent.putExtra("aspectY", 1);
        photoPickerIntent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
        photoPickerIntent.putExtra(MediaStore.EXTRA_OUTPUT, getTempUri());
        startActivityForResult(photoPickerIntent, PICK_FROM_GALLERY);
        } 
    }
    

    find my complete solution here in stackoverflow post

提交回复
热议问题