Loading Large-Sized Image from Stream in .NET MAUI on Android Throws Java.Lang.RuntimeException #31830
Replies: 3 comments
-
Hi @TamilarasanGunasekaran, I cloned the repo and since your image is within your app, you can include it in Resources -> Images (to change the image build action to MauiAction) |
Beta Was this translation helpful? Give feedback.
-
I had the same problem, try setting image width and height request in your xaml, that what helped me. On iOS it was autosizing to fit conteiners, on Android had to explicitly set width and height otherwise it was crashing, even for smaller images. |
Beta Was this translation helpful? Give feedback.
-
I would recommend switching from Microsoft.Maui.Controls.Image to SkiaSharp.Views.Maui.Controls.SKCanvasView from SkiaSharp.Views.Maui.Controls for rendering your bitmaps, as it’s faster and uses less memory. Also, <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:skia="clr-namespace:SkiaSharp.Views.Maui.Controls;assembly=SkiaSharp.Views.Maui.Controls"
xmlns:local="clr-namespace:ImageLoadingIssueOnAndroid"
x:Class="ImageLoadingIssueOnAndroid.MainPage">
<ContentPage.Content>
<!--
<Image x:Name="image"/>
-->
<skia:SKCanvasView x:Name="canvasView" PaintSurface="canvasView_PaintSurface" />
</ContentPage.Content>
</ContentPage> public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
/*
image.Source = ImageSource.FromStream(() => typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("ImageLoadingIssueOnAndroid.Assets.imagebig.png"));
*/
}
private async void canvasView_PaintSurface(object sender, SkiaSharp.Views.Maui.SKPaintSurfaceEventArgs e)
{
// Load from EmbeddedResource placed in Assets/imagebig.png
// var imageStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("ImageLoadingIssueOnAndroid.Assets.imagebig.png");
// Load from MauiAsset placed in Resources/Raw/imagebig.png
var imageStream = await FileSystem.OpenAppPackageFileAsync("imagebig.png");
SKSurface surface = e.Surface;
SKCanvas canvas = surface.Canvas;
SKBitmap bitmap = SKBitmap.Decode(imageStream);
canvas.Clear();
canvas.DrawBitmap(bitmap, e.Info.Rect);
}
} See my PR: TamilarasanGunasekaran/Image_loading_issue_android#1 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
We are encountering an issue when attempting to load large-sized images(3344x33) from a stream in a .NET MAUI application, specifically on the Android platform. The application crashes with a Java.Lang.RuntimeException, severely impacting performance and stability.
Observed Behavior:
Windows Platform:
The image loads successfully from the stream without any issues.
Android Platform:
Attempting to load the same image from a stream results in a Java.Lang.RuntimeException. This crash occurs consistently with large image sizes.
Questions for the Framework Team:
Reproducible Sample: Click Here!
Beta Was this translation helpful? Give feedback.
All reactions