Oreo版本问题中的此图像不支持编辑 [英] Editing is not supported for this Image in Oreo Version problem

查看:84
本文介绍了Oreo版本问题中的此图像不支持编辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此图像在Oreo版本中不支持编辑.

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

(此图像不支持编辑)此Toast在Oreo版本移动设备中从图库中选择图像时显示.我已经问过这个问题,但是没人回答我.请检查我的代码,然后尽快还原.

(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.

这是我的代码:-

@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();
    }
}

推荐答案

将Uri添加到文件中

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

我还尝试传递由 FileProvider.getUriForFile(< file object>)生成的Uri,并且有效.

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

这篇关于Oreo版本问题中的此图像不支持编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆