最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

android - How to load image file from (external) storage to .NET MAUI Image? - Stack Overflow

programmeradmin0浏览0评论

Setup:

  • .NET MAUI 8
  • VS 2022 17.9.7
  • Windows 11 24H2
  • Samsung SM-A715F (Android 13.0 - API 33)

XAML:

<Image x:Name="MyImage"
       HeightRequest="160"
       Aspect="AspectFit"/>

Code-behind:

protected override void OnAppearing()
{
    base.OnAppearing();
    var filePath = Path.Combine(FileSystem.AppDataDirectory, 
                                "test.jpg");
    if (File.Exists(filePath))
    {
        MyImage.Source = ImageSource.FromFile(filePath);
    }
}

It seems the above only works on Windows. It does NOT work on Android.

The following permissions are set in AndroidManifest.xml:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />

I do NOT want to use FilePicker or anything like that.

The question is plain and simple: how to load image file from storage to .NET MAUI Image?

This GitHub issue seems related and still open since 2022! Anyone knows a workaround or third-party component that sorts this out?

发布评论

评论列表(0)

  1. 暂无评论