dotnet / dotnet/maui

[Android] Loading image from stream throws Java.Lang.RuntimeException when large sized image view is used

Open
#11,230 8 comments 4 reactions 0 assignees View on GitHub
area-controls-image platform/android s/triaged s/verified t/bug
Dominant language
C#
Stars
23.3k
Forks
2k
Avg merge
1d 15h
Merged PRs (30d)
290

Description

### Description

When loading image from stream, it throws **Java.Lang.RuntimeException** when larger sized image views are used. To view banner sized images, we needed to show it in a larger image view example (3000 x 3000). But it throws the following exception in Android platform when doing the same. This too occurs when loading image from stream as we are creating image at run time and load it as stream.

**_It occurs when testing in mobile device_**

image

### Steps to Reproduce

1. Download, and build the attached project (which is linked in the public project repository).
2. Select the framework as Android.
3. Connect the Android mobile device and select it.
4. Deploy the project.
5. Click the button "Show Image". The exception will occur.
* In the button click, I have created an image view with 3000 x 3000 and loading a image from stream at run time.

Expected outcome: Image should be shown.
Actual outcome: Java.Lang.RuntimeException is thrown.

### Link to public reproduction project repository

https://github.com/Deepak1799/NET-MAUI-Samples/tree/master/AndroidImageIssue

### Version with bug

6.0.486 (current)

### Last version that worked well

Unknown/Other

### Affected platforms

Android

### Affected platform versions

Android 9.0

### Did you find any workaround?

When setting **android:hardwareAccelerated="false"** in the Android manifest file, the issue does not occurs. But is not recommended to force in the application.

### Relevant log output

```shell
Java.Lang.RuntimeException
Message=Canvas: trying to draw too large(301121496bytes) bitmap.
```

Contributor guide

Open the contributing guide

Research direction

Start by running the linked AndroidImageIssue reproduction project on an Android 9 device and reproduce the 3000 x 3000 stream-loaded image failure. Inspect the Android image-loading and rendering entry points in the MAUI repository, comparing behavior with and without android:hardwareAccelerated="false". Done means large stream-loaded images display without the Java.Lang.RuntimeException while preserving normal hardware acceleration.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, csharp
Domain
mobile-dev, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.