翻譯|使用教程|編輯:況魚杰|2021-03-11 14:40:40.973|閱讀 137 次
概述:TX Text Control .NET 15.0時已引入頁面渲染引擎,該引擎使您可以導出每個單獨頁面的圖元文件或位圖。 這使開發人員可以創建頁面的縮略圖或導出圖像以在瀏覽器中查看它們。 此示例說明如何從文檔的所有頁面創建多頁TIFF圖像。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
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微信公眾號 ???,了解產品的最新動態及最新資訊。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自: