[英]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.