在 Blazor 中如何将图像加载到内存中以便 C# 可以访问它

In Blazor how do you load an image into memory so C# can access it

我确定这是我错过的简单操作,但我需要从网络服务器加载来自 WASM Blazor 的图像,以便我可以将其打印为 PDF 文件。打印不是问题。我只需要将它加载到内存流或我可以转换为内存流的东西中。

我仔细研究了很久,终于找到了这个问题的答案。我是愚蠢的,但以防万一有人需要知道这里的答案是:

public class DownloadBinFile 
{
    private HttpClient client;
    public DownloadBinFile(HttpClient http_)
    {
        client = http_;
    }
    public async Task<Stream> Download(string url)
    {
        var response = await client.GetAsync($"{url}");
        response.EnsureSuccessStatusCode();
        Stream ms;
        ms = await response.Content.ReadAsStreamAsync();
        return ms;
    }
}