【问题标题】:MvvmCross.Plugins.File: A Downloaded and locally stored image is not displayed in MvxImageViewMvvmCross.Plugins.File:MvxImageView 中不显示下载和本地存储的图像
【发布时间】:2014-05-28 12:57:44
【问题描述】:

我从网上保存了一张这样的图片:

public void SetSelectedConsultant(string consultantId)
{
    // ...

    var path = this.fileStore.PathCombine(App.IMAGES_FOLDER, App.SELECTED_CONSULTANT_IMAGE_FILENAME);

    if (this.fileStore.Exists(path))
    {
        this.fileStore.DeleteFile(path);
    }

    this.fileStore.EnsureFolderExists(App.IMAGES_FOLDER);

    this.GeneralAsyncLoad(
        App.SERVER_URL + App.CONSULTANT_FILE_NAME,
        stream =>
            {
                this.SaveConsultantImage(stream, path);
                this.mvxMessenger.Publish(new ConsultantUpdatedMessage(this));
            });
}

private void SaveConsultantImage(Stream stream, string path)
{
    var memoryStream = new MemoryStream();
    stream.CopyTo(memoryStream);
    byte[] pictureBytes = memoryStream.ToArray();

    this.fileStore.WriteFile(path, pictureBytes);
}

ConsultantUpdatedMessage 被我的视图模型捕获,它将为ConsultantImageUrl 提高属性更改。我的其他属性(如 ConsultantName 等)在视图中正确刷新,但图像拒绝显示在控件中:

<Mvx.MvxImageView
    android:scaleType="fitXY"
    android:layout_margin="5dp"
    android:layout_width="220dp"
    android:layout_height="wrap_content"
    local:MvxBind="ImageUrl ConsultantImageUrl" />

我检查了文件是否存在,使用 fileStore.Exists,结果为“true”,但文件不会显示。是不是我保存图片的方式不对?

编辑:作为操作指南,我使用了本教程 (https://github.com/MvvmCross/NPlus1DaysOfMvvmCross/tree/master/N-16-CollectABull-Part5)。但是,他们使用本地相册中的照片而不是下载照片。

【问题讨论】:

  • 您能否添加更多代码来说明如何在视图模型中使用 ConsultantImageUrl?您在调试跟踪中看到什么奇怪的东西吗?

标签: xamarin mvvmcross


【解决方案1】:

我发现了问题。网址错误,它下载了另一个(无图像)文件并保存了它。因此那里存在一个文件,但无法在视图中显示,因为它不是图像。

【讨论】:

    猜你喜欢
    • 2019-01-05
    • 1970-01-01
    • 1970-01-01
    • 2020-12-29
    • 2016-11-19
    • 1970-01-01
    • 1970-01-01
    • 2014-07-13
    • 2018-12-10
    相关资源
    最近更新 更多