C# 从多页tiff-c中提取帧#
有一个多页tiff,我想从这个tiff文件中提取page[n]/frame[n]并保存它 如果我的多页tiff有3帧,在我提取一页/帧后-我想留下 1个图像,具有2页/帧和C# 从多页tiff-c中提取帧#,c#,C#,有一个多页tiff,我想从这个tiff文件中提取page[n]/frame[n]并保存它 如果我的多页tiff有3帧,在我提取一页/帧后-我想留下 1个图像,具有2页/帧和 1个图像只有1页/帧。以下是一些代码,用于将多帧tiff中的最后一帧保存到单页tiff文件中。 (要使用此代码,需要添加对PresentationCore.dll的引用) 使用,提取页面是一个简单的单行程序: convert input.tif[page] output.tif 要提取一系列页面,请将[page]替换为[f
1个图像只有1页/帧。以下是一些代码,用于将多帧tiff中的最后一帧保存到单页tiff文件中。
(要使用此代码,需要添加对PresentationCore.dll的引用) 使用,提取页面是一个简单的单行程序:
convert input.tif[page] output.tif
要提取一系列页面,请将[page]
替换为[frompage topage]
。需要注意的是,页面计数从零开始
在您的情况下,您必须运行该命令两次,但ImageMagick功能强大,我敢打赌还有另一个单行命令可以按您想要的方式执行拆分
从未使用过C#,因此我不知道这是否可以在代码中使用。要使用此代码,您需要添加对PresentationCore.dll的引用,该引用可以在“[Program Files]/reference Assembly”文件夹中找到。此程序集包含“System.Windows.Media.Imaging”命名空间。
public void SaveFrame(string path, int frameIndex, string toPath)
{
using (FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
{
BitmapDecoder dec = BitmapDecoder.Create(stream, BitmapCreateOptions.IgnoreImageCache, BitmapCacheOption.None);
BitmapEncoder enc = BitmapEncoder.Create(dec.CodecInfo.ContainerFormat);
enc.Frames.Add(dec.Frames[frameIndex]);
using (FileStream tmpStream = new FileStream(toPath, FileMode.Create))
{
enc.Save(tmpStream);
}
}
}
convert input.tif[page] output.tif