0

我创建了一个小型 .net core 3.1 控制台应用程序,以使用 Magick.Net ( https://www.nuget.org/packages/Magick.NET-Q16-AnyCPU/ ) 将 pdf 转换为 png。我还安装了 ghostscript 公共许可证。一切正常,但输出图像完全是黑色的,我无法读取一行。如果我使用 Paint 打开文件,那就没问题了。这是我的代码:

        public static int ConvertFileToImages(string filePath, string destinationPath)
        {
            int noofPages = 0;
            MagickReadSettings magickReadSettings = new MagickReadSettings();
            magickReadSettings.Density = new Density(300, 300);
            using (MagickImageCollection magickImageCollection = new MagickImageCollection())
            {
                magickImageCollection.Read(filePath, magickReadSettings);
                int page = 1;
                noofPages = magickImageCollection.Count;
                foreach (MagickImage magickImage in magickImageCollection)
                {
                    magickImage.Format = MagickFormat.Png;
                    magickImage.BackgroundColor = MagickColors.White;
                    string imageFilePath = string.Concat(destinationPath, "file-", page, ".png");
                    magickImage.Write(imageFilePath);
                    page++;
                }
            }
            return noofPages;
        }

我做错什么了吗?

4

0 回答 0