我正在尝试做什么:
在我的应用程序中,我具有上传图像的功能。我想在我的 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());
}
关于c# - Azure 中的图像格式更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60151215/