Xamarin.forms 空对象引用上的android.contentResolver

Xamarin.forms 空对象引用上的android.contentResolver,xamarin.forms,Xamarin.forms,您好,我在Stream grapes=ContentResolver.OpenInputStream(selectedImage)一行收到以下异常,图像不是空的,我在视图中使用它,所以可能我引用错误了 JavaLang空指针异常,尝试在空对象引用上调用虚拟方法android.contentResolver public String ScanService() { var selectedImage = Android.Net.Uri.Parse(&quo

您好,我在
Stream grapes=ContentResolver.OpenInputStream(selectedImage)一行收到以下异常,图像不是空的,我在视图中使用它,所以可能我引用错误了

JavaLang空指针异常,尝试在空对象引用上调用虚拟方法android.contentResolver

public String ScanService()
        {
            var selectedImage = Android.Net.Uri.Parse("@Resources/drawable/portrait.png");
            Stream grapes = ContentResolver.OpenInputStream(selectedImage); 
            var options = new BitmapFactory.Options();
            options.InJustDecodeBounds = true;
            BitmapFactory.DecodeStream(grapes, null, options);
            string test = "test";
            
            Parsing(test);
            return test;
        }
我已经尝试过这个
Android.Net.Uri.Parse(“Android。resource://demoregapp.android/drawable/portrait.png");
基于此,

https://stackoverflow.com/questions/6602417/get-the-uri-of-an-image-stored-in-drawable

但我还是得到了同样的异常

我看不到您在方法中使用位图

如果要从资源中的图像创建位图,可以使用:

public String ScanService()
{
    //var selectedImage = Android.Net.Uri.Parse("@Resources/drawable/portrait.png");
    //Stream grapes = ContentResolver.OpenInputStream(selectedImage);
    //var options = new BitmapFactory.Options();
    //options.InJustDecodeBounds = true;
    //BitmapFactory.DecodeStream(grapes, null, options);

    BitmapFactory.DecodeResource(Resources, Resource.Drawable.portrait);

    string test = "test";            
    Parsing(test);
    return test;
}