【问题标题】:Unable to preview multiple page tiff files in .Net无法在 .Net 中预览多个页面 tiff 文件
【发布时间】:2009-04-14 18:11:14
【问题描述】:

我正在尝试从 C# 2005 Windows 应用程序预览和打印多页 TIFF 文件。打印工作正常,但是当我将 PrintDocument 发送到 PrintPreviewDialog 时,我得到第一页的两个图像,而不是第一页和第二页的图像。我在使用 PrintPreviewControl 时也遇到了同样的问题。

下面是带有 2 个按钮、一个 PrintDocument 和一个 PrintPreviewDialog 的表单的代码,用于演示该问题。

public partial class Form1 : Form
{
    private Image m_Image;
    private Int32 m_CurrentPage;
    private Int32 m_PageCount;

    private void Form1_Load(object sender, EventArgs e)
    {
        m_Image = Image.FromFile(".\\Test-2-Page-Image.tif");
        m_PageCount = m_Image.GetFrameCount(FrameDimension.Page);
    }

    private void printDocument_BeginPrint(object sender, PrintEventArgs e)
    {
        m_CurrentPage = 0;
        m_PageCount = m_Image.GetFrameCount(FrameDimension.Page);
    }

    private void printDocument_PrintPage(object sender, PrintPageEventArgs e)
    {
        m_Image.SelectActiveFrame(FrameDimension.Page, m_CurrentPage);
        e.Graphics.DrawImage(m_Image, 0, 0);
        ++m_CurrentPage;
        e.HasMorePages = (m_CurrentPage < m_PageCount);
    }

    private void btnPreview_Click(object sender, EventArgs e)
    {
        printPreviewDialog.Document = printDocument;
        printPreviewDialog.ShowDialog();
    }

    private void btnPrint_Click(object sender, EventArgs e)
    {
        printDocument.Print();
    }
}

有谁知道 .Net 框架中的 PrintPreviewDialog 是否存在问题,或者我做错了什么。

【问题讨论】:

    标签: c# .net printing preview


    【解决方案1】:

    这是Graphics.DrawImage() 函数的错误。

    问题记录在这里:Graphics.DrawImage Bug

    工作代码如下所示:

    img.SelectActiveFrame(FrameDimension.Page, curPage);
    using(MemoryStream stm = new MemoryStream())
    {     
        img.Save(stm, imgCodecInfo, encParams); // save to memory stream
        Bitmap bmp = (Bitmap)Image.FromStream(stm);
        e.Graphics.DrawImage((Image)bmp,0,0);
        bmp.Dispose();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-27
      相关资源
      最近更新 更多