我有一些包含多个页面的 tif 文件,我想将其转换为单个长页面。即,包含两页(每页尺寸为 8.5x11)的文件将转换为大小为 8.5x22 的结果文件。有没有办法去掉分页符?
我不是询问如何将多个文件转换为单个文件。
最佳答案
我已经解决了这个问题。以下代码的大部分来自 Scott Hanselman上this page .
此 C# 函数采用源图像的文件名及其 tiff 输出的保存位置:
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);
}
}
}
关于image-processing - 删除多页 tif 中的分页符以形成一页长页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13313594/