c# - Image' is an ambiguous reference between 'System.Drawing.Image' and 'iText.Layout.Element.Image'
问题描述
With that code I can split a multi tiff and save the images to files.
public void SplitImage(string file)
{
Bitmap bitmap = (Bitmap)Image.FromFile(file);
int count = bitmap.GetFrameCount(FrameDimension.Page);
var new_files = file.Split("_");
String new_file = new_files[new_files.Length - 1];
for (int idx = 0; idx < count; idx++)
{
bitmap.SelectActiveFrame(FrameDimension.Page, idx);
bitmap.Save($"C:\\temp\\{idx}-{new_file}", ImageFormat.Tiff);
}
}
here the code for the Pdf creation
public void CreatePDFFromImages(string path_multi_tiff)
{
Image img = new Image(ImageDataFactory.Create(path_multi_tiff));
var p = new Paragraph("Image").Add(img);
var writer = new PdfWriter("C:\\temp\\test.pdf");
var pdf = new PdfDocument(writer);
var document = new Document(pdf);
document.Add(new Paragraph("Images"));
document.Add(p);
document.Close();
Console.WriteLine("Done !");
}
now I would like to save the images to pdf pages and tried it with iText7. But this fails as
using System.Drawing.Imaging;
using Image = iText.Layout.Element.Image;
are to close to have them both in the same class. How could I save the splitted images to PDF pages ? I would like to avoid saving first to files and reloading all the images.
解决方案
The line
using Image = iText.Layout.Element.Image;
is a so-called using alias directive. It creates the alias Image
for the namespace or type iText.Layout.Element.Image
. If this poses a problem, you can simply create a different alias. For example
using A = iText.Layout.Element.Image;
will create the alias A
for the namespace or type iText.Layout.Element.Image
.
推荐阅读
- python - 如何获取实例的名称以影响 tkinter 标签
- javascript - 将项目转换为 Typescript 路径时遇到问题
- excel - 尝试刷新 activex 列表框填充范围时出现自动化错误 404
- c - Arduino 作为 I2C 从机与 RPi 对话
- python - 查找两个数据帧/列表中字符串之间的差异,输出差异
- protocol-buffers - 如何在协议缓冲区中存储单个字节?
- javascript - 是对象 Ramda 内的数组或字符串中的值
- macos - 带有 brew 的 Macos 上的多个版本的 .Net Core
- python - python脚本失败时的日志
- docker - 将 WSL VSCode 扩展连接到安装在 Windows 中的 docker