首页 > 解决方案 > 如何将从json获取的字节数组更改为图像

问题描述

我将图像和数据存储在数据库中,我有.net Core API,它发回包含一些数据和图像数组的对象。如何以角度在页面上显示该图像?我尝试使用FileReader和它的功能readAsDataURL,但我不能让它工作和/或不能将图像转换为 blob。

从 API 发回的对象模型:

    public class ControlPoint
{
    public int Id { get; set; }
    public string Location { get; set; }
    public string Confirmation { get; set; }
    public ICollection<Image> Images { get; set; }
    public ControlPointType Type { get; set; }
}

图像模型:

public class Image
{
    public int Id { get; set; }
    public Guid ROWGUID { get; set; }
    public string FileName { get; set; }
    public DateTime DateAdded { get; set; }
    public int ControlPointId { get; set; }
    public byte[] Stream { get; set; }
}

角度控制点模型:

export interface ControlPoint {
    id: number;
    location: string;
    confirmation: string;
    images: Photo[];
    type: ControlPointType;
}

角度图像模型:

export class Photo {
    fileName: string;
    dateAdded: Date;
    controlPointId: number;
    stream: any;
}

我该如何处理?我认为我无法将响应类型更改为 blob,因为我在 json 中获取了整个对象,而不仅仅是图像。

标签: javascriptangulartypescript.net-core

解决方案


推荐阅读