Editing is not supported for this Image in Oreo Version problem

跟風遠走 提交于 2021-02-07 12:44:07

问题


Editing is not supported for this Image in Oreo Version problem.

(Editing is not supported for this Image)this Toast showing when select the Image from gallery in Oreo Version mobile. I already asked this question but no one reply me. Please check my code and revert back as soon as possible.

This is my code:-

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

    if (resultCode != 0) {
        if (requestCode == GALLERY_CAPTURE) {              
            picUri = data.getData();               
            String[] filePathColumn = {MediaStore.Images.Media.DATA};
            Cursor cursor = getContext().getContentResolver().query(picUri, filePathColumn, null, null, null);
            cursor.moveToFirst();
            int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
            String picturePath = cursor.getString(columnIndex);            
            performCrop();
        }            
        else if (requestCode == CROP_PIC) {             
            Bundle extras = data.getExtras();            
            Bitmap thePic = extras.getParcelable("data");
            rimage.setImageBitmap(thePic);
            getCroppedBitmap(thePic);
            Uri tempUri = getImageUri(getActivity(), thePic);
            finalFile = new File(getRealPathFromURI(tempUri));
            Log.e("cropped Image Path", String.valueOf(finalFile));
        }
    }
}

public Uri getImageUri(Context inContext, Bitmap inImage) {
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    inImage.compress(Bitmap.CompressFormat.PNG, 100, bytes);
    String path = MediaStore.Images.Media.insertImage(inContext.getContentResolver(), inImage, "Title", null);
    return Uri.parse(path);
}

public String getRealPathFromURI(Uri uri) {
    Cursor cursor = getContext().getContentResolver().query(uri, null, null, null, null);
    cursor.moveToFirst();
    int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
    return cursor.getString(idx);
}

public Bitmap getCroppedBitmap(Bitmap bitmap) {
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
            bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(output);
    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2,
            bitmap.getWidth() / 2, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    return output;
}

private void performCrop() {        
    try {            
        Intent cropIntent = new Intent("com.android.camera.action.CROP");            cropIntent.setClassName("com.prince","com.prince.RegisterStepThree");           
        cropIntent.setDataAndType(picUri, "image/*");         
        cropIntent.putExtra("crop", "true");           
        cropIntent.putExtra("aspectX", 1);
        cropIntent.putExtra("aspectY", 1);            
        cropIntent.putExtra("outputX", 96);
        cropIntent.putExtra("outputY", 96);         
        cropIntent.putExtra("return-data", true);             
        startActivityForResult(cropIntent, CROP_PIC);
    }       
    catch (ActivityNotFoundException anfe) {
        Toast toast = Toast
                .makeText(getContext(), "This device doesn't support the crop action!", Toast.LENGTH_SHORT);
        toast.show();
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }
}

回答1:


Add the Uri to the file to the intent

intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(<file object>);

I also tried passing the Uri generated by FileProvider.getUriForFile(<file object>) and that worked.




回答2:


Using intent.putExtra(MediaStore.EXTRA_OUTPUT, uri) looks like the right answer in several actions including ACTION_EDIT and MediaStore.ACTION_IMAGE_CAPTURE.

Notice that in modern API the URI should be created using FileProvider



来源:https://stackoverflow.com/questions/52110987/editing-is-not-supported-for-this-image-in-oreo-version-problem

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!