admin管理员组文章数量:1391977
I want to show large images to users, the images can get 5MB in size and easily get around 7000*7000. I get image in byte[] array from server.
There is no problem displaying it on IOS device, the only issue is with android device which gives a weird java error "Java.Lang.RuntimeException:Canvas: trying to draw too large(134640000bytes) bitmap."
I already have functionality to zoom in/out and move image in any direction. Can someone please help, I tried to look everywhere but found nothing.
Edit: I am getting bytes[] so loading image like this MainImage.Source = ImageSource.FromStream(() => new MemoryStream(imagebytes));
I want to show large images to users, the images can get 5MB in size and easily get around 7000*7000. I get image in byte[] array from server.
There is no problem displaying it on IOS device, the only issue is with android device which gives a weird java error "Java.Lang.RuntimeException:Canvas: trying to draw too large(134640000bytes) bitmap."
I already have functionality to zoom in/out and move image in any direction. Can someone please help, I tried to look everywhere but found nothing.
Edit: I am getting bytes[] so loading image like this MainImage.Source = ImageSource.FromStream(() => new MemoryStream(imagebytes));
- Thanks Austin, but i looked at that and there is no solution, they have lots of issues similar to that opened, but people are saying implement platform specific code use some kind of bitmaps – Khushwinder Singh Commented Mar 12 at 20:05
- 1 How are we supposed to know what “weird Java error” is? Please read How to Ask before posting – Jason Commented Mar 13 at 1:06
- @KhushwinderSingh try this github/dotnet/maui/issues/18834#issuecomment-2664924970 – Bhavanesh N Commented Mar 13 at 6:10
- @KhushwinderSingh fix your question by adding the at least the error message. There is zero value in it, the way it is phrased right now. – H.A.H. Commented Mar 13 at 12:18
- 1 @KhushwinderSingh I removed my close vote, and upvoted your question. – H.A.H. Commented Mar 13 at 13:25
2 Answers
Reset to default 3I'm assuming you are using Image. When dealing with large images, FFImageLoading is your friend. Since you have not specified the extension of your image file, I'm going to post how you could load a SVG image and other formats like JPG:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft/winfx/2009/xaml"
xmlns:ffimageloading="clr-namespace:FFImageLoading.Maui;assembly=FFImageLoading.Maui"
xmlns:ffimageloadingsvg="clr-namespace:FFImageLoading.Maui;assembly=FFImageLoading.Maui">
<!--Use this one for SVG-->
<ffimageloadingsvg:SvgCachedImage x:Name="MainImage" HorizontalOptions="Center" VerticalOptions="Center"/>
<!--Use this one for other formats like JPG-->
<!--<ffimageloading:CachedImage x:Name="MainImage" HorizontalOptions="Center" VerticalOptions="Center"/>-->
</ContentPage>
You can change the source as you did before:
MainImage.Source = ImageSource.FromStream(() => new MemoryStream(imagebytes));
First, this is not a bug.
It is how the situation is with android, even more true for old devices.
I suggest alternative solution, that I used for android native code. The idea is that you do not need to display 7000x7000 image in first place.
What you would want to do is resize the image in memory, and then display the resized image. There are libraries that I use in android native code, that do this in one line.
So I would be surprised if SkiaSharp (or something similar) would lack this functionality. But on MAUI I have never used it. I apply resize (force limitations) at the back-end when the image is getting uploaded at first place.
Just an alternative point of view.
本文标签:
版权声明:本文标题:c# - Android devices fail to handle large images in .net maui app, IOS devices are great - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744732355a2622123.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论