无法从 TiffBitmapDecoder.Frames 检索 TIFF 页 - 所有帧都是第 1 页
我正在尝试将多页 tiff 图像转换为多页 XPS 文档。 我遇到的问题是 TiffBitmapDecoder 及其 BitmapFrames。
代码如下:
private static void ToXpsDocument(string imageName, string xpsName)
{
using (var p = Package.Open(xpsName))
{
PackageStore.AddPackage(new Uri("pack://thedocloljk.xps"), p);
XpsDocument doc = new XpsDocument(p);
var writer = XpsDocument.CreateXpsDocumentWriter(doc);
var dec = new TiffBitmapDecoder
(new Uri(imageName),
BitmapCreateOptions.IgnoreImageCache,
BitmapCacheOption.None);
var fd = new FixedDocument();
foreach (var frame in dec.Frames)
{
var image = new System.Windows.Controls.Image();
image.Source = frame;
var fp = new FixedPage();
fp.Children.Add(image);
fp.Width = frame.Width;
fp.Height = frame.Height;
var pc = new PageContent();
(pc as IAddChild).AddChild(fp);
fd.Pages.Add(pc);
}
writer.Write(fd);
p.Flush();
p.Close();
PackageStore.RemovePackage(new Uri("pack://thedocloljk.xps"));
}
}
这会生成具有正确页数的 XPS。 但是,每个页面都是 tiff 第一页的副本。 事实上,如果我挑选一个帧(例如 dec.Frames[4])并将其写入磁盘,它看起来就像第一页。
我到底做错了什么? 这些框架实际上不是图像的各个页面吗? 我怎样才能让他们出去并与他们一起工作???
I'm trying to convert a multipage tiff image into a multipage XPS document. The problem I'm having is with the TiffBitmapDecoder and its BitmapFrames.
Here's the code:
private static void ToXpsDocument(string imageName, string xpsName)
{
using (var p = Package.Open(xpsName))
{
PackageStore.AddPackage(new Uri("pack://thedocloljk.xps"), p);
XpsDocument doc = new XpsDocument(p);
var writer = XpsDocument.CreateXpsDocumentWriter(doc);
var dec = new TiffBitmapDecoder
(new Uri(imageName),
BitmapCreateOptions.IgnoreImageCache,
BitmapCacheOption.None);
var fd = new FixedDocument();
foreach (var frame in dec.Frames)
{
var image = new System.Windows.Controls.Image();
image.Source = frame;
var fp = new FixedPage();
fp.Children.Add(image);
fp.Width = frame.Width;
fp.Height = frame.Height;
var pc = new PageContent();
(pc as IAddChild).AddChild(fp);
fd.Pages.Add(pc);
}
writer.Write(fd);
p.Flush();
p.Close();
PackageStore.RemovePackage(new Uri("pack://thedocloljk.xps"));
}
}
This results in an XPS with the correct number of pages. However, every page is a replica of the first page of the tiff. In fact, if I pick out a single frame (say, dec.Frames[4]) and write it to disk, it looks like the first page.
What the heck am I doing wrong here? Are the frames not actually the individual pages of the image? How can I get them out and work with them???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用以下代码(注释行与您的版本不同):
Try using the following code (the commented lines are different than your version):