question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Image cannot display device picture.

See original GitHub issue

Description

Image cannot display device picture which in “/data/user/0/app/cache/xxx.png”, it’s display as blank.

And my code as follow:

MainPage.xaml:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="MauiApp1.MainPage">

    <StackLayout>
        <Button Clicked="Button_Clicked" Text="Pick"></Button>
        <Image x:Name="Img" Source="dotnet_bot.png" WidthRequest="300" HeightRequest="300" ></Image>
    </StackLayout>
</ContentPage>

MainPage.xaml.cs

namespace MauiApp1
{
    public partial class MainPage : ContentPage
    {
        int count = 0;

        public MainPage()
        {
            InitializeComponent();
        }

        private async void Button_Clicked(object sender, EventArgs e)
        {
            var photo = await MediaPicker.PickPhotoAsync();

            var newFile = Path.Combine(FileSystem.CacheDirectory, photo.FileName);
            using (var stream = await photo.OpenReadAsync())
            using (var newStream = File.OpenWrite(newFile))
                await stream.CopyToAsync(newStream);

            await DisplayAlert("newFile", newFile, "OK");
            Img.Source = newFile;
        }
    }
}

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
	<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="31" />
	<application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true"></application>
	<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />


	<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
	<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
	<uses-permission android:name="android.permission.CAMERA" />
	<queries>
		<intent>
			<action android:name="android.media.action.IMAGE_CAPTURE" />
		</intent>
	</queries>
</manifest>

BTW, is there any way to pick images from gallery?

Steps to Reproduce

  1. Create a File > New .NET MAUI App
  2. Replace MainPage ans AndroidManifest with the code
  3. connect the local device
  4. run

Version with bug

Release Candidate 1

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

API 30

Did you find any workaround?

Affected platforms: Only tried on Android

Relevant log output

I don't know how to get it, maybe the official can give a tutorial, thanks a lot.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
zxyao145commented, May 11, 2022

@zxyao145 RC3 has been released just now which should make it all work again! Could you update and let us know? 😃

Perfect! In RC3, it works as expected. And I think this issue can be closed. Thank you!

0reactions
msftbot[bot]commented, May 10, 2022

Hi @zxyao145. We have added the “s/needs-info” label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ImageView displaying in layout but not on actual device
When I choose to view the Graphical Layout of the UI it displays the imageview correctly at the bottom of the activity. However,...
Read more >
Message: windows photo viewer can't display this picture ...
Under Devices tab tick "Use My Settings" for this device. Highlight and delete the profile associated with this device. Check the images.
Read more >
How to fix pictures not showing in gallery of Android device
How to fix pictures not showing in gallery of Android device | Images missing from gallery Subscribe to my channel: ...
Read more >
How to Fix if Images are Not Showing in the Gallery of Android ...
In case if you want to move this photo to the gallery what you do is ... I don't have the same display...
Read more >
How to fix picture not showing up in phone gallery - YouTube
I can't see photos phone gallery -fixed Subscribe to my Channel: ... Photo Not Show In Gallery Samsung || Pictures / Pics Are...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found