1

我一直在研究这个库,目的是在 C# 中制作图像处理管道。我希望它能够接收 .png 图像并将其转换为 .jpeg。但是我还没有找到使用这个库的方法。甚至可能吗?有没有人能够成功地做到这一点?

这是我最好的镜头:

Image<Rgba32> image1 = SixLabors.ImageSharp.Image.Load<Rgba32>(fileName, out IImageFormat format);

var encd = new JpegEncoder
                {
                    Quality = 80
                };

image.Save(outputFinalPath, encd);

结果是图像被简单地保存为 .png。我是处理图像的新手,所以我可能会遗漏一些东西。

4

1 回答 1

2

all you have to do to load an image from any PNG file then call save passing a path to a file with a jpg file extension.

using (var img = Image.Load("path/to/inputImage.png"))
{
    img.Save("path/to/outputImage.jpeg");
}

optionally passing a jpeg encoder to tweak settings, or you could also just change the defaults using the below code

Configuration.Default.ImageFormatsManager.SetEncoder(JpegFormat.Instance, new JpegEncoder()
{
    Quality = 90
});
于 2020-10-21T20:24:46.857 回答