SixLabors ImageSharp 的文档非常有限,而且大多数 google 搜索都指向 GitHub,这不是很有帮助。
如何上传.Mutate
带有透明填充的jpg并将其保存为具有透明度的png?
这是我到目前为止的代码。如果上传的图像是 png,则透明填充有效,但 jpg 得到黑色填充:
private static void ResizeAndSavePhoto(Image<Rgba32> img, string path, int squareSize)
{
Configuration.Default.ImageFormatsManager.SetEncoder(PngFormat.Instance, new PngEncoder()
{
ColorType = PngColorType.RgbWithAlpha
});
img.Mutate(x =>
x.Resize(new ResizeOptions
{
Size = new Size(squareSize, squareSize),
Mode = ResizeMode.Pad
}).BackgroundColor(new Rgba32(255, 255, 255, 0))
);
img.Save(path);
return;
}
.SaveAsPng()
需要一个文件流,但我有一个Image<Rgba32>
和一个路径......