Crop saved Image using com.android.camera.action.CROP on android

前端 未结 4 1666
温柔的废话
温柔的废话 2020-12-21 09:27

I have reads many question about this, but I still failed using this code... maybe anyone can corect my code... I want to crop an image from file that i know the location us

4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-21 09:47

        try {
            Intent intent = new Intent("com.android.camera.action.CROP");
            intent.setDataAndType(mPhotoUri, "image/*");
            intent.putExtra("crop", "true");
            Integer altura = documento.getAltura();
            Integer largura = documento.getLargura();
            if (altura != null && largura != null) {
                intent.putExtra("aspectY", altura);
                intent.putExtra("aspectX", largura);
            }
            File file = imagemProcessor.getNewFile();
            mCropUri = Uri.fromFile(file);
            intent.putExtra(MediaStore.EXTRA_OUTPUT, mCropUri);
            intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
            startActivityForResult(intent, REQUEST_IMAGE_CROP);
        } catch (ActivityNotFoundException e) {
            Context context = getBaseContext();
            Toast toast = Toast.makeText(context, "Your device doesn't support the crop action!", Toast.LENGTH_SHORT);
            toast.show();
        } catch (IOException e) {
            Context context = getBaseContext();
            Toast toast = Toast.makeText(context, "Fail to create file!", Toast.LENGTH_SHORT);
            toast.show();
        }
    

提交回复
热议问题