'XImage' 不包含 'GetFrameCount' 的定义

'XImage' does not contain a definition for 'GetFrameCount'

我正在尝试创建多页 TIFF 到 PDF 转换器。我从 Internet 上的多个来源跟踪了看起来不错的代码。我安装了 PDFsharp-gdi,我相信我已经包含了适当的库。

问题是我收到错误消息:

Error CS1061 'XImage' does not contain a definition for 'GetFrameCount' and no extension method 'GetFrameCount' accepting a first argument of type 'XImage' could be found (are you missing a using directive or an assembly reference?)

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
...
using System.IO;
using PdfSharp;
using PdfSharp.Pdf;
using PdfSharp.Pdf.IO;
using PdfSharp.Drawing;
...
for (int i = 0; i < prePdfFiles.Count; i++)
{
    PdfDocument doc = new PdfDocument();
    XGraphics xgr;
    XImage img = XImage.FromFile(destPath + prePdfFiles[i]);
    int pagesCount = img.GetFrameCount(FrameDimension.Page);
    for( int j = 0; j < pagesCount; j++ )
    {
        img.SelectActiveFrame(FrameDimension.Page, j);
        PdfPage currentPage = new PdfPage();
        doc.Pages.Add(currentPage);
        xgr = XGraphics.FromPdfPage(currentPage);
        XImage ximg = XImage.FromGdiPlusImage(img);
        xgr.DrawImage(ximg, 0, 0);
    }
    doc.Save(System.IO.Path.ChangeExtension(destPath + prePdfFiles[i], ".pdf"));
    doc.Close();
}

如果 XImage 没有该方法,请使用 Image class 并稍后转换为 XImage