删除多页Tif中的分页符以使一页变长 [英] Remove page breaks in multi-page tif to make one long page

查看:173
本文介绍了删除多页Tif中的分页符以使一页变长的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些带有多个页面的tif文件,我想将其转换为单个长页面.即包含两个分别为8.5x11的页面的文件将被转换为大小为8.5x22的结果文件.有什么办法可以删除分页符?

I have some tif files with multiple pages that I would like to convert to a single long page. i.e. a file including two pages that are each 8.5x11 would be converted to a resulting file of size 8.5x22. Is there any way to remove the page breaks?

我不是不是问如何将多个文件转换为单个文件.

I am not asking how to convert multiple files into a single file.

推荐答案

我已经解决了这个问题.以下代码中的很大一部分来自 Scott Hanselman . ://www.hanselman.com/blog/CompositingTwoImagesIntoOneFromTheASPNETServerSide.aspx"rel =" nofollow noreferrer"title ="此页>此页.

I have solved this. A good chunk of the following code comes from Scott Hanselman on this page.

此C#函数使用源图像的文件名和其tiff输出的保存位置:

This C# function takes a filename for the source image and a save location for its tiff output:

public static void RemovePageBreaks(string fileInput, string fileOutput)
        {
            using (Image image = Image.FromFile(fileInput))
            using (MemoryStream m = new MemoryStream())
            {
                int width = image.Width;
                int height = 0;
                int pageCount = image.GetFrameCount(FrameDimension.Page);
                height = image.Height * pageCount;
                int pasteFrom = 0;
                using (Bitmap compositeImage = new Bitmap(width, height))
                using (Graphics compositeGraphics = Graphics.FromImage(compositeImage))
                {
                    compositeGraphics.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
                    for (int page = 0; page < pageCount; page++)
                    {

                        image.SelectActiveFrame(FrameDimension.Page, page);
                        image.Save(m, image.RawFormat);
                        Rectangle rect = new Rectangle(0, pasteFrom, image.Width, image.Height);
                        compositeGraphics.DrawImageUnscaledAndClipped(image, rect);
                        pasteFrom += image.Height;
                    }
                    compositeImage.Save(fileOutput, System.Drawing.Imaging.ImageFormat.Tiff);
                }

            }
        }

这篇关于删除多页Tif中的分页符以使一页变长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆