简体   繁体   English

我正在做一个Xamarin跨平台项目,无法在UI上显示uri图像。 我总是得到一个错误,说位图太大

[英]I am doing a Xamarin cross platform project and can't display uri images on my UI. I always get this an error saying the bitmap is too large

I am doing a Xamarin project for school and can't display any uri images on my user interface. 我正在为学校做一个Xamarin项目,并且无法在用户界面上显示任何uri图像。 I always get this error in the debug window: 我总是在调试窗口中收到此错误:

java.lang.RuntimeException: Canvas: trying to draw too large(241238816bytes) bitmap. java.lang.RuntimeException:画布:试图绘制太大(241238816bytes)的位图。

This is cross platform so I can't just set a height and width request and Xamarin does the work for me. 这是跨平台的,所以我不能只设置高度和宽度请求,Xamarin会为我完成工作。 I can't just download picasso or FFImageLoading from Nuget and pass a few parameters because this is Android AND iOS. 我不能只是从Nuget下载picasso或FFImageLoading并传递一些参数,因为这是Android和iOS。 No UWP by the way. 顺便说一句,没有UWP。 Just Android and iOS. 仅限Android和iOS。 I saw something on Github for resizing images but that's for image files, not uri's. 我在Github上看到了一些用于调整图像大小的内容,但这是用于图像文件,而不是uri的。 Saving the uri image as a file first doesn't work because most of them are 200+ MB each! 首先将uri映像另存为文件是行不通的,因为它们大多数每个文件大小都超过200 MB! I need to pass the "Image" source to the ImageSource.FromUri(new Uri(myUriIWantToPass)); 我需要将“图像”源传递给ImageSource.FromUri(new Uri(myUriIWantToPass)); I understand I am probably going to have to write code to pass the uri string, height request, width request. 我了解我可能将不得不编写代码以传递uri字符串,高度请求,宽度请求。 Make a new Bitmap that's scaled down. 制作一个按比例缩小的新位图。 Then load it and then set the Image source to the new scaled down bitmap somehow. 然后加载它,然后将Image源以某种方式设置为新的按比例缩小的位图。 I will copy and paste code for the backend of the page. 我将复制并粘贴页面后端的代码。 It's called PlantProfilePage.xaml.cs and that code should be enough to go by for an answer. 它被称为PlantProfilePage.xaml.cs,并且该代码应该足以为您解答。

protected override void OnAppearing()
        {
            base.OnAppearing();
            FamilyName.BindingContext = this;
            GenusName.BindingContext = this;
            ScientificName.BindingContext = this;
            //PlantPicture.Source = ImageSource.FromUri(new Uri(uriList[0].ToString()));
            string url = "https://collections.nmnh.si.edu/media/index.php?irn=11986034";
            //string encodedURL = Uri.EscapeDataString(url);
            try
            {
                WebRequest request = WebRequest.Create(url);
                request.BeginGetResponse((IAsyncResult arg) =>
                {
                    Stream stream = request.EndGetResponse(arg).GetResponseStream();
                    ImageSource imageSource = ImageSource.FromStream(() => stream);
                    Device.BeginInvokeOnMainThread(() => PlantPicture.Source = imageSource);
                }, null);

                //PlantPicture.Source = UriImageSource.FromUri(new Uri(url));
            }
            catch (UriFormatException ufe)
            {
                Debug.WriteLine("Uri didn't work: " + ufe);
            }

I need to resize these uri string's I'm using from hundreds of megabytes to something that won't cause the project to give me the error: 我需要将我正在使用的这些uri字符串的大小从数百兆字节调整到不会导致项目给我错误的内容:

java.lang.RuntimeException: Canvas: trying to draw too large(241238816bytes) bitmap. java.lang.RuntimeException:画布:试图绘制太大(241238816bytes)的位图。

This should work for both Android and iOS both. 这应该同时适用于Android和iOS。

The FFImageLoading worked. FFImageLoading工作正常。 It will show scaled down uri images for the Android and iPhone screen. 它将在Android和iPhone屏幕上显示按比例缩小的uri图像。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法让我不敏感的用户登录功能工作,我做错了什么? Xamarin 表单 - Can't get my insensitive user login function to work, what am I doing wrong? Xamarin forms 在我的 Xamarin 表单(跨平台)中使用 WCF Web 服务时出现错误 - I'm getting a error while consuming the WCF Webservice in my Xamarin forms(cross platform) 我在Visual Studio 2017上找不到跨平台应用程序Xamarin - I can't find cross platform app Xamarin on visual studio 2017 我正在尝试将 MVVM 实现到我的 xamarin 应用程序中,但它崩溃说“索引器不包含右括号” - I am trying to implement MVVM into my xamarin app, but it crashes saying 'indexer did not contain closing bracket' 安装 Windows 服务然后尝试运行时,我收到错误 1053。说我的服务启动时间过长 - When installing Windows service and then trying to run, I get an Error 1053. Saying my service is taking too long to start 使用Task.Run()异步压缩会阻止UI。 我想念什么? - Zipping asynchronously using Task.Run() is blocking UI. What am I missing? Subversion是否会污染我的项目,或者我做错了什么? - Is Subversion polluting my project, or am I doing something wrong? 我的代码中出现错误:找不到表0。我在做什么错? - I get an error in my code: Cannot find table 0. what am I doing wrong? 出现错误,找不到Xamarin跨平台项目的资源 - Getting error no resource found for Xamarin cross platform Project 我将我的项目升级到 .NET Framework 4.8 和新的包格式,现在我收到一条错误消息,提示 System.Net.Http 丢失 - I upgraded my project to .NET Framework 4.8 and the new package format, and now I get an error saying System.Net.Http is missing
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM