我在 xamarin.forms 工作。我有一个列表页面,我想在其中加载一组图像。图像是从 Web 服务加载的,而不是从本地设备加载的。有些图像尺寸很大,所以我使用 ffImageLoading 插件进行图像压缩。
我的问题是一些图像路径没有加载。当我向下滚动页面图像可能会加载。我还想提一下,相同的图像路径在浏览器中正确打开,因此确认没有防火墙限制。
我已经制作了示例项目,其中我手动填充了列表对象而不是 Web 服务。某些图像未加载。我无法弄清楚这是路径问题还是插件问题。
<ListView x:Name="listView" HasUnevenRows="True" Grid.Row="1">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid BackgroundColor="#eee">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<ffimageloading:CachedImage Source="{Binding image}" LoadingPlaceholder="placeholder.jpg" RetryCount="5" DownsampleToViewSize="True" Grid.Column="0" HeightRequest="120" WidthRequest="120"/>
<!--<Image Source="{Binding image}" Grid.Column="0" HeightRequest="120" WidthRequest="120"/>-->
<StackLayout Grid.Column="1">
<Label Text="{Binding title}" TextColor="#f35e20" />
<Label Text="{Binding subtitle}" TextColor="#503026" />
</StackLayout>
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
public partial class ImageLoading : ContentPage
{
List<ImageList> lstImages;
public ImageLoading()
{
InitializeComponent();
lstImages = new List<ImageList>();
var service = DependencyService.Get<ICompressImage>();
lstImages.Add(new ImageList { image = "https://www.cpsc.gov/s3fs-public/Model%20Year%202017%20800PRO-RMK%20155SC%20Indy%20Red.jpg", title = "Image1", subtitle = "Image1 Description" });
lstImages.Add(new ImageList { image = "https://www.cpsc.gov/s3fs-public/2017%20Honda%20Pioneer%20700%20side-by-side%20%28Red.jpg", title = "Image2", subtitle = "Image2 Description" });
lstImages.Add(new ImageList { image = "https://www.fda.gov/ucm/groups/fdagov-public/documents/image/UCM557581.png", title = "Image3", subtitle = "Image3 Description" });
lstImages.Add(new ImageList { image = "http://www.nafpaktia.com/data/wallpapers/2/727787.jpg", title = "Image4", subtitle = "Image4 Description" });
lstImages.Add(new ImageList { image = "https://www.fda.gov/ucm/groups/fdagov-public/documents/image/UCM557126.jpg", title = "Image5", subtitle = "Image5 Description" });
lstImages.Add(new ImageList { image = "https://www.fda.gov/ucm/groups/fdagov-public/documents/image/UCM557109.png", title = "Image6", subtitle = "Image6 Description" });
lstImages.Add(new ImageList { image = "https://www.cpsc.gov/s3fs-public/PT-OffBoardCharger.jpeg", title = "Image7", subtitle = "Image7 Description" });
lstImages.Add(new ImageList { image = "https://www.fda.gov/ucm/groups/fdagov-public/documents/image/UCM556528.png", title = "Image8", subtitle = "Image8 Description" });
lstImages.Add(new ImageList { image = "https://www.fda.gov/ucm/groups/fdagov-public/documents/image/UCM556528.png", title = "Image9", subtitle = "Image9 Description" });
lstImages.Add(new ImageList { image = "https://www.cpsc.gov/s3fs-public/PT-OffBoardCharger.jpeg", title = "Image10", subtitle = "Image10 Description" });
}
protected override void OnAppearing()
{
base.OnAppearing();
listView.ItemsSource = lstImages;
}
}
public class ImageList
{
public byte[] byteImage { get; set; }
public string image { get; set; }
public string title { get; set; }
public string subtitle { get; set; }
}
正如您在上面的代码中看到的,我已经在列表视图中加载了一些图像集。
https://www.fda.gov/ucm/groups/fdagov-public/documents/image/UCM557581.png
所有以“ https://www.fda.gov ”基本 URL开头的图像都不会加载。
有些图像带有相同的路径。因此,ffimageloading 的行为可能会有所不同。我不知道确切的原因。
如果我使用简单的图像控制,那么有什么方法可以为 android 压缩图像?