c# - Azure 中的图像格式更改

标签 c# image azure azure-functions

我正在尝试做什么: 在我的应用程序中,我具有上传图像的功能。我想在我的 Azure 函数 中将上传的图像更改为 PNG 格式,无论用户选择什么格式。

我尝试过的:

我尝试了System.Drawing,但由于沙盒限制,它在 Azure 中不起作用。

我尝试了Magick.NET,但它使内存流损坏。

我想向您学习这方面的经验。

谢谢

最佳答案

您可以使用与.netcore兼容的ImageSharp,并且不依赖于System.Drawing:

private static void ResizeAndSavePhoto(Image<Rgba32> img, string path, int squareSize)
{
    img.Mutate(x =>
        x.Resize(new ResizeOptions
        {
            Size = new Size(squareSize, squareSize),
            Mode = ResizeMode.Pad
        }).BackgroundColor(new Rgba32(255, 255, 255, 0)));

    // The following demonstrates how to force png encoding with a path.
    img.Save(Path.ChangeExtension(path, ".jpg"))

    img.Save(path, new PngEncoder());
}

更多信息:https://github.com/SixLabors/ImageSharp

来自:https://stackoverflow.com/a/58761261/1384539

关于c# - Azure 中的图像格式更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60151215/

相关文章:

c# - 'System.Data.DataRowCollection' 不包含 "Length"的定义

c# - 什么是更好的设计/实践 : Nullable property or 1 value property and 1 bool "has" property?

iphone - 如何从 unsigned char * 创建图像

Android YuvImage 类格式不正确?

azure - Microsoft Teams 通知间歇性停止工作

azure - 如何使用 PowerShell 跨 Azure 订阅列出资源组?

Azure 服务总线订阅者死信

c# - DataContractJsonSerializer 跳过具有空值的节点

c# - 跳过并接受 Entity Framework Core

iphone - iOS iPhone : Why does my image rotation skew the image?