0

我正在尝试使用 pdfium 查看器将 pdf 导出为 jpeg。如何指定 jpeg 图像的颜色深度?我是否必须使用 System.Drawing.Imaging 编辑流,或者有人知道使用 pdfium 的方法吗?https://github.com/pvginkel/PdfiumViewer是我用来渲染 pdf 和创建图像的工具。

 using (var document = PdfiumViewer.PdfDocument.Load(file.ToString()))
                    {
                        for (int page = 0; page < document.PageCount; page++)
                        {
                            var image = document.Render(page, 2550, 3300, 72, 72, false);

                            image.Save(filepath + "\\" + filename + "-" + (page + 1) + ".jpg", ImageFormat.Jpeg);

                        }
                    }
4

1 回答 1

0

必须设置图像编码器属性才能更改它们。这从颠簸到tiff都显示出来,但解释了我在寻找什么。

using System;
using System.Drawing;
using System.Drawing.Imaging;
class Example_SetColorDepth
{
    public static void Main()
    {
        Bitmap myBitmap;
        ImageCodecInfo myImageCodecInfo;
        Encoder myEncoder;
        EncoderParameter myEncoderParameter;
        EncoderParameters myEncoderParameters;

        // Create a Bitmap object based on a BMP file.
        myBitmap = new Bitmap(@"C:\Documents and Settings\All Users\Documents\My Music\music.bmp");

        // Get an ImageCodecInfo object that represents the TIFF codec.
        myImageCodecInfo = GetEncoderInfo("image/tiff");

        // Create an Encoder object based on the GUID
        // for the ColorDepth parameter category.
        myEncoder = Encoder.ColorDepth;

        // Create an EncoderParameters object.
        // An EncoderParameters object has an array of EncoderParameter
        // objects. In this case, there is only one
        // EncoderParameter object in the array.
        myEncoderParameters = new EncoderParameters(1);

        // Save the image with a color depth of 24 bits per pixel.
        myEncoderParameter =
            new EncoderParameter(myEncoder, 24L);
        myEncoderParameters.Param[0] = myEncoderParameter;
        myBitmap.Save("Shapes24bpp.tiff", myImageCodecInfo, myEncoderParameters);
    }

    private static ImageCodecInfo GetEncoderInfo(String mimeType)
    {
        int j;
        ImageCodecInfo[] encoders;
        encoders = ImageCodecInfo.GetImageEncoders();
        for(j = 0; j < encoders.Length; ++j)
        {
            if(encoders[j].MimeType == mimeType)
                return encoders[j];
        }
        return null;
    }
}
于 2019-10-05T00:23:09.923 回答