有一个多页 tiff,我想从此 Tiff 文件中提取第 [n] 页/帧 [n] 并保存它。
如果我的多页 tiff 有 3 帧,在我提取一页/帧后 - 我想留下
1 张图像有 2 页/帧,并且
1 张图像只有 1 页/帧。
下面是一些代码,用于将多帧 tiff 中的最后一帧保存到单页 tiff 文件中。
(为了使用此代码,您需要添加对PresentationCore.dll 的引用)。
Stream imageStreamSource = new FileStream(imageFilename, FileMode.Open, FileAccess.Read, FileShare.Read);
MemoryStream memstream = new MemoryStream();
memstream.SetLength(imageStreamSource.Length);
imageStreamSource.Read(memstream.GetBuffer(), 0, (int)imageStreamSource.Length);
imageStreamSource.Close();
BitmapDecoder decoder = TiffBitmapDecoder.Create(memstream,BitmapCreateOptions.PreservePixelFormat,BitmapCacheOption.Default);
Int32 frameCount = decoder.Frames.Count;
BitmapFrame imageFrame = decoder.Frames[0];
MemoryStream output = new MemoryStream();
TiffBitmapEncoder encoder = new TiffBitmapEncoder();
encoder.Frames.Add(imageFrame);
encoder.Save(output);
FileStream outStream = File.OpenWrite("Image.Tiff");
output.WriteTo(outStream);
outStream.Flush();
outStream.Close();
output.Flush();
output.Close();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)