TX Text Control系列教程—Windows Forms:如何创建多页TIFF图像

TX Text Control .NET 15.0时已引入页面渲染引擎,该引擎使您可以导出每个单独页面的图元文件或位图。 这使开发人员可以创建页面的缩略图或导出图像以在浏览器中查看它们。 此示例说明如何从文档的所有页面创建多页TIFF图像。

TX Text Control .NET for Windows Forms 是一套功能丰富的文字处理控件,它以可重复使用控件的形式为开发人员提供了Word中常用的文字处理功能,对于需要强大且灵活的文档处理能力的应用程序而言,是理想的选择。

TX Text Control .NET for Windows Forms X19试用版


TX Text Control .NET 15.0时已引入页面渲染引擎,该引擎使您可以导出每个单独页面的图元文件或位图。 这使开发人员可以创建页面的缩略图或导出图像以在浏览器中查看它们。 此示例说明如何从文档的所有页面创建多页TIFF图像。

创建这些映像需要两个重要步骤:

  • 使用页面渲染引擎创建TIFF图像

  • 将这些图像合并为一个TIFF图像

首先,需要遍历TX Text Control的所有页面以创建单独的TIFF图像:

ArrayList inputImages = new ArrayList();foreach (Page page in textControl1.GetPages()){    MemoryStream image = new MemoryStream();    Bitmap bitmap = page.GetImage(100, TXTextControl.Page.PageContent.All);    bitmap.Save(image, ImageFormat.Tiff);    inputImages.Add(image);}

每个TIFF图像都存储在一个内存流中,该内存流被添加到ArrayList中,以便在组合它们时更容易处理。

在第二步骤中,将TIFF图像合并为单个图像。 因此,创建一个新图像,以便使用SaveAdd方法将ArrayList中的所有其他图像附加到新图像的新框架中。

public static void CreateMultipageTIF(ArrayList InputImages, string Filename){    // set the image codec    ImageCodecInfo info = null;    foreach (ImageCodecInfo ice in ImageCodecInfo.GetImageEncoders())    {        if (ice.MimeType == "image/tiff")        {            info = ice;            break;        }    }    EncoderParameters ep = new EncoderParameters(2);    bool firstPage = true;    System.Drawing.Image img = null;    // create an image instance from the 1st image    for (int nLoopfile = 0; nLoopfile < InputImages.Count; nLoopfile++)    {        //get image from src file        System.Drawing.Image img_src = System.Drawing.Image.FromStream((Stream)InputImages[nLoopfile]);        Guid guid = img_src.FrameDimensionsList[0];        System.Drawing.Imaging.FrameDimension dimension = new System.Drawing.Imaging.FrameDimension(guid);        //get the frames from src file        for (int nLoopFrame = 0; nLoopFrame < img_src.GetFrameCount(dimension); nLoopFrame++)        {            img_src.SelectActiveFrame(dimension, nLoopFrame);            ep.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Compression, Convert.ToInt32(EncoderValue.CompressionLZW));            // if first page, then create the initial image            if (firstPage)            {                img = img_src;                ep.Param[1] = new EncoderParameter(System.Drawing.Imaging.Encoder.SaveFlag, Convert.ToInt32(EncoderValue.MultiFrame));                img.Save(Filename, info, ep);                firstPage = false;                continue;            }            // add image to the next frame            ep.Param[1] = new EncoderParameter(System.Drawing.Imaging.Encoder.SaveFlag, Convert.ToInt32(EncoderValue.FrameDimensionPage));            img.SaveAdd(img_src, ep);        }    }    ep.Param[1] = new EncoderParameter(System.Drawing.Imaging.Encoder.SaveFlag, Convert.ToInt32(EncoderValue.Flush));    img.SaveAdd(ep);}

文章推荐:

TX Text Control系列教程—Windows Forms:创建应用程序


如果您对Text Control感兴趣,可以咨询在线客服>>购买正版授权软件。

关注慧聚IT微信公众号 了解产品的最新动态及最新资讯。

标签:

来源:慧都

声明:本站部分文章及图片转载于互联网,内容版权归原作者所有,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2021年1月8日
下一篇 2021年1月8日

相关推荐

发表回复

登录后才能评论