【问题标题】:Xamarin - Image from URI isn't rendered despite being seemingly downloadedXamarin - 尽管看似已下载,但未呈现来自 URI 的图像
【发布时间】:2020-04-03 00:25:06
【问题描述】:

让我先说对不起,如果这已经在某个地方得到了回答,我搜索了很长时间,但找不到有效的答案。

所以根据标题,我有一个非常简单的应用程序,它实际上只有一个页面,应该显示来自 URI 的一张图像,仅此而已。由于某种原因,在物理设备或模拟器上部署时,图像都不会显示。图片工作正常,它只是来自网络 (http://thumbs.dreamstime.com/z/watercolor-autumn-forest-landscape-sunset-hand-drawn-painting-fantasy-art-nature-beautiful-background-gouache-153834924.jpg) 的随机图片。我附加了 ActivityIndi​​cator,它在一秒钟后停止旋转,所以我假设图像已加载,因此应用程序未连接到网络并只是图像渲染不是问题...

我尝试将 Android 选项 -> 高级 -> HttpClient 实现设置为托管,将 SSL/TLS 实现设置为原生 TLS 1.2+,以及 Android 清单 -> 所需权限 -> 互联网。都没有帮助。我尝试使用 http:// 和 https://,也没有结果。我现在很困惑。

这是我的 App.xaml.cs:

using System;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
using App1.Services;
using App1.Views;

namespace App1
{
    public partial class App : Application
    {
        public App()
        {
            InitializeComponent();

            DependencyService.Register<MockDataStore>();
            MainPage = new ImagePage();
        }
    }
}

这是 ImagePage.xaml.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace App1
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class ImagePage : ContentPage
    {
        public ImagePage()
        {
            InitializeComponent();

            var imageSource = new UriImageSource { Uri = new Uri("http://thumbs.dreamstime.com/z/watercolor-autumn-forest-landscape-sunset-hand-drawn-painting-fantasy-art-nature-beautiful-background-gouache-153834924.jpg") };
            imageSource.CachingEnabled = false;

            image.Source = imageSource;
        }
    }
}

这是此页面的 xaml:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:d="http://xamarin.com/schemas/2014/forms/design"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             mc:Ignorable="d"
             x:Class="App1.ImagePage">
    <AbsoluteLayout>
        <ActivityIndicator IsRunning="{Binding Source={x:Reference image}, Path=IsLoading}" AbsoluteLayout.LayoutBounds="0.5, 0.5, 100, 100" AbsoluteLayout.LayoutFlags="PositionProportional"/>
        <Image IsVisible="True" x:Name="image"/>
    </AbsoluteLayout>
</ContentPage>

我将不胜感激任何帮助:)。正如我所说,这非常简单,我不知道为什么此时这不起作用。

【问题讨论】:

  • 那个 url 返回一个 HTTP 301。我认为你选择了一个不好的例子

标签: c# android image xamarin xamarin.forms


【解决方案1】:

你的Xamarin.Forms 版本是什么?Xamarin.forms 版本4.2.0.778463 早期有一个issue reported,它已在 Xamarin.forms 版本4.2.0.848062 中修复。

所以你可以尝试更新你的Xamarin.forms 版本

【讨论】:

  • 谢谢!似乎就是这样。我有你在这里提到的确切版本并更新修复了这个错误。奇怪的是,这样的事情怎么会溜走。也很奇怪,我找不到这个......无论如何,对不起,谢谢!
猜你喜欢
  • 2021-03-19
  • 2021-10-25
  • 1970-01-01
  • 2019-08-18
  • 1970-01-01
  • 2020-10-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多