繁体   English   中英

如何将变量传递给 MagicImage

[英]How to pass variable into MagicImage

我正在尝试使用 MagicImage 将 HEIC 转换为 JPEG,因此我的 newFile.Data 包含发送到服务器的图像的字节 []。 所以我很确定我的代码是正确的,但是当我将图像发送到服务器时,即 web 它以 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()
            });

不就是这样吗?

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()
        });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM