Toolkit DrawingView is giving AndroidRuntime] java.lang.RuntimeException: Canvas: trying to draw too large(216039040bytes) bitmap.

Shashank Gaddam [C] 20 Reputation points
2025-04-03T06:03:18.98+00:00

Toolkit DrawingView is giving AndroidRuntime] java.lang.RuntimeException: Canvas: trying to draw too large(216039040bytes) bitmap when I draw a single horizontal line after reading from Memory stream

 await using var stream = await DrawingView.GetImageStream(512, 512);

 using var memoryStream = new MemoryStream();

 stream.CopyTo(memoryStream);

 stream.Position = 0;

 memoryStream.Position = 0;

 var imageBytes = memoryStream.ToArray();

 var SignatureBase64 = Convert.ToBase64String(imageBytes);

var SignatureImageSource = ImageSource.FromStream(() => new MemoryStream(Convert.FromBase64String(SignatureBase64)));

Developer technologies .NET .NET MAUI
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 50,126 Reputation points Microsoft External Staff
    2025-04-04T02:08:27.29+00:00

    Hello,

    This error is expected. The process of converting DrawingView to an image stream is actually very complicated, and you cannot directly assign it to an Image by reading the stream. You need to convert it through the API provided by DrawingView.

    Please refer to the following documents and code examples.

    private async void DrawingView_DrawingLineCompleted(object sender, CommunityToolkit.Maui.Core.DrawingLineCompletedEventArgs e)
    {
        var imgstream = await DrawingView.GetImageStream(desiredWidth: 400, desiredHeight: 300, imageOutputOption: DrawingViewOutputOption.FullCanvas);
        test_img.Source = ImageSource.FromStream(() => imgstream);
    }
    

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.