Crop an image when selected from gallery in android

后端 未结 6 554
佛祖请我去吃肉
佛祖请我去吃肉 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:23

    You can already tell the Camera/Gallery-Intent to start the crop-editor after the image is selected/taken:

    Pick Image from Gallery:

    Intent pickImageIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    
    pickImageIntent.setType("image/*");
    pickImageIntent.putExtra("crop", "true");
    pickImageIntent.putExtra("outputX", 200);
    pickImageIntent.putExtra("outputY", 200);
    pickImageIntent.putExtra("aspectX", 1);
    pickImageIntent.putExtra("aspectY", 1);
    pickImageIntent.putExtra("scale", true);
    pickImageIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriWhereToStore);
    pickImageIntent.putExtra("outputFormat",
    
    Bitmap.CompressFormat.JPEG.toString());
    startActivityForResult(pickImageIntent, RESULT_LOAD_IMAGE);
    

    Take Photo:

    Intent takePicIntent = new Intent("android.media.action.IMAGE_CAPTURE");
    
    takePicIntent .putExtra("crop", "true");
    takePicIntent .putExtra("outputX", 200);
    takePicIntent .putExtra("outputY", 200);
    takePicIntent .putExtra("aspectX", 1);
    takePicIntent .putExtra("aspectY", 1);
    takePicIntent .putExtra("scale", true);
    takePicIntent .putExtra(MediaStore.EXTRA_OUTPUT, uriWhereToStore);
    takePicIntent .putExtra("outputFormat",
    
    Bitmap.CompressFormat.JPEG.toString());
    startActivityForResult(takePicIntent , RESULT_LOAD_IMAGE);
    

提交回复
热议问题