【问题标题】:How to pass variable into MagicImage如何将变量传递给 MagicImage
【发布时间】:2021-12-27 20:40:08
【问题描述】:

我正在尝试使用 MagicImage 将 HEIC 转换为 JPEG,因此我的 newFile.Data 包含发送到服务器的图像的字节 []。所以我很确定我的代码是正确的,但是当我将图像发送到服务器(即网络)时,它会以 HEIC 格式上传,但我需要它的 jpeg 格式。所以我被困在这里,无法弄清楚我需要做什么

using (var image = new MagickImage(newFile.Data))
{
    // Sets the output format to jpeg
    image.Format = MagickFormat.Jpeg;

    // Create byte array that contains a jpeg file
    byte[] data = image.ToByteArray();
}

var currentFiles = 
            _clientFileService.Value.GetFilesByClient(clientId).Where(x => x.ClientFileType == type).Select(x => x.Id).ToList();

_clientFileService.Value.MultipleDelete(currentFiles, null);

_clientFileService
    .Value
    .AddFile(
    new ClientFile
    {
        Data = newFile.Data, // How can I pass MagickImage to newFile.Data
        Guid = Guid.NewGuid()
    });

【问题讨论】:

    标签: c# imagemagick


    【解决方案1】:

    我认为你需要在 fileService 中使用 MagikImage 的数据:

    byte[] data = null;
    using (var image = new MagickImage(newFile.Data))
    {
        // Sets the output format to jpeg
        image.Format = MagickFormat.Jpeg;
    
        // Create byte array that contains a jpeg file
        data = image.ToByteArray();
    }
    
    var currentFiles = _clientFileService.Value
        .GetFilesByClient(clientId)
        .Where(x => x.ClientFileType == type)
        .Select(x => x.Id)
        .ToList();
    
    _clientFileService.Value.MultipleDelete(currentFiles, null);
    
    _clientFileService
        .Value
        .AddFile(new ClientFile
        {
            Data = data 
            Guid = Guid.NewGuid()
        });
    

    【讨论】:

      猜你喜欢
      • 2021-05-25
      • 2018-12-28
      • 2011-04-12
      • 2017-01-24
      • 2018-05-17
      • 2012-04-20
      • 2018-03-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多