tiff 到 PDF 转换中的反转颜色
我确信我在这里犯了一些愚蠢的错误,但是当将 tiff 文件转换为 PDF 时,颜色会反转。我不明白为什么。这是我的代码:
Document document = new Document(PageSize.A4, 50, 50, 50, 50);
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream("Image.pdf", FileMode.Create));
System.Drawing.Bitmap bm = new System.Drawing.Bitmap(@"C:\Temp\338814-00.tif");
int total = bm.GetFrameCount(FrameDimension.Page);
document.Open();
PdfContentByte cb = writer.DirectContent;
for (int k = 0; k < total; ++k)
{
bm.SelectActiveFrame(FrameDimension.Page, k);
MemoryStream ms = new MemoryStream();
bm.Save(ms, ImageFormat.Tiff);
Image img = Image.GetInstance(ms.ToArray());
img.ScalePercent(72f / (float)img.DpiX * 100);
img.SetAbsolutePosition(0, 0);
cb.AddImage(img);
document.NewPage();
}
document.Close();
谢谢。
I'm sure I'm making some kind of silly mistake here, but when converting a tiff file to PDF, the colours become reversed. I can't figure out why. Here's my code:
Document document = new Document(PageSize.A4, 50, 50, 50, 50);
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream("Image.pdf", FileMode.Create));
System.Drawing.Bitmap bm = new System.Drawing.Bitmap(@"C:\Temp\338814-00.tif");
int total = bm.GetFrameCount(FrameDimension.Page);
document.Open();
PdfContentByte cb = writer.DirectContent;
for (int k = 0; k < total; ++k)
{
bm.SelectActiveFrame(FrameDimension.Page, k);
MemoryStream ms = new MemoryStream();
bm.Save(ms, ImageFormat.Tiff);
Image img = Image.GetInstance(ms.ToArray());
img.ScalePercent(72f / (float)img.DpiX * 100);
img.SetAbsolutePosition(0, 0);
cb.AddImage(img);
document.NewPage();
}
document.Close();
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最好的解决方案似乎是替换该行:
使用
Png 似乎可以为 Tiff 图像提供最佳的速度/文件大小性能。为什么这有效我仍然不知道。
The best solution appears to be to replace the line:
with
Png seems to give the best speed/file size performance for Tiff images. Why this works I still have no idea.