Android 无法在图像视图中查看我的原始照片

Android 无法在图像视图中查看我的原始照片,android,Android,我是android的新手。在我的应用程序中,我有一个图像视图。我想看到相机拍摄的照片。但当我拍摄照片时,它会自动旋转并在图像视图中显示。我使用了旋转功能,但当时发生了错误 主要活动 错误:java.lang.SecurityException:权限拒绝:读取com.android.providers.media.MediaProvider uricontent://media/external/images/media 从pid=16783开始,uid=10085需要android.permis

我是android的新手。在我的应用程序中,我有一个图像视图。我想看到相机拍摄的照片。但当我拍摄照片时,它会自动旋转并在图像视图中显示。我使用了旋转功能,但当时发生了错误

主要活动

错误:java.lang.SecurityException:权限拒绝:读取com.android.providers.media.MediaProvider uricontent://media/external/images/media 从pid=16783开始,uid=10085需要android.permission.READ\u EXTERNAL\u存储或grantUriPermission()


当我添加此旋转功能时,图像视图中未显示任何图片。并且显示此错误。请帮助我。

您在AndroidMenifest.xml文件中授予的权限以及android目标设备的版本。当我添加此旋转功能时,目标sdk版本27<代码>显示了此错误。。不可能的。rotateImage()仅处理位图。
getImageOrientation()
。那应该得到什么样的定位?您指的不是特定的图像。
image.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            startActivityForResult(intent,101 );

        }
    });
}

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

    try {
        switch (requestCode) {
            case 101:
                if (resultCode == Activity.RESULT_OK) {
                    if (data != null) {
                        selectedImage = data.getData(); // the uri of the image taken
                        if (String.valueOf((Bitmap) data.getExtras().get("data")).equals("null")) {
                            bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), selectedImage);
                        } else {
                            bitmap = (Bitmap) data.getExtras().get("data");
                        }
                        if (Float.valueOf(getImageOrientation()) >= 0) {
                            bitmapRotate = rotateImage(bitmap, Float.valueOf(getImageOrientation()));
                        } else {
                            bitmapRotate = bitmap;
                            bitmap.recycle();
                        }


                        image.setImageBitmap(bitmapRotate);

                       //   Saving image to mobile internal memory for sometime
                        String root = getApplicationContext().getFilesDir().toString();
                        File myDir = new File(root + "/androidlift");
                        myDir.mkdirs();

                        Random generator = new Random();
                        int n = 10000;
                        n = generator.nextInt(n);

                        //   Give the file name that u want
                        fname = "null" + n + ".jpg";

                        imagepath = root + "/androidlift/" + fname;
                        file = new File(myDir, fname);
                        upflag = true;
                    }
                }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    super.onActivityResult(requestCode, resultCode, data);

}

public static Bitmap rotateImage(Bitmap source, float angle) {
    Bitmap retVal;

    Matrix matrix = new Matrix();
    matrix.postRotate(angle);
    retVal = Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true);

    return retVal;
}

//    In some mobiles image will get rotate so to correting that this code will help us
private int getImageOrientation() {
    final String[] imageColumns = {MediaStore.Images.Media._ID, MediaStore.Images.ImageColumns.ORIENTATION};
    final String imageOrderBy = MediaStore.Images.Media._ID + " DESC";
    Cursor cursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
            imageColumns, null, null, imageOrderBy);// error line

    if (cursor.moveToFirst()) {
        int orientation = cursor.getInt(cursor.getColumnIndex(MediaStore.Images.ImageColumns.ORIENTATION));
        System.out.println("orientation===" + orientation);
        cursor.close();
        return orientation;
    } else {
        return 0;
    }
}