C# 保存使用PdfPig提取的图像
我正在使用C#在一个控制台应用程序(.Net Core)项目中试验PdfPig 以下代码旨在从PDF获取图像并将其保存到我的桌面:C# 保存使用PdfPig提取的图像,c#,.net,pdf,console-application,C#,.net,Pdf,Console Application,我正在使用C#在一个控制台应用程序(.Net Core)项目中试验PdfPig 以下代码旨在从PDF获取图像并将其保存到我的桌面: IEnumerable<IPdfImage> images = page.GetImages(); foreach (IPdfImage image in images) { Console.WriteLine(image); byte[] bitmap = image.RawBytes.ToArray(); string ex
IEnumerable<IPdfImage> images = page.GetImages();
foreach (IPdfImage image in images)
{
Console.WriteLine(image);
byte[] bitmap = image.RawBytes.ToArray();
string exportPath = @"C:\Users\ed\Desktop\" + Guid.NewGuid().ToString() + ".jpg";
System.IO.File.WriteAllBytes(exportPath, bitmap);
}
请有人建议如何修改这个;我怀疑我是如何创建图像文件的
谢谢大家! 假设pdf图像的原始字节构成jpg图像。事实并非如此,pdf有许多位图格式,这是正确的。你知道我能识别并导出正确文件格式的方法吗?看起来这些图像是tif文件,我从你的问题“CCITTFaxDecode”中提取的。
XObject Image (w 595.1999999999999, h 841.92): <Type, /XObject>, <Subtype, /Image>, <Width, 2480>, <Height, 3508>, <BitsPerComponent, 1>, <ColorSpace, /DeviceGray>, <Filter, /CCITTFaxDecode>, <DecodeParms, <Columns, 2480>, <Rows, 3508>>, <Length, 381787>
XObject Image (w 595.1999999999999, h 841.92): <Type, /XObject>, <Subtype, /Image>, <Width, 2480>, <Height, 3508>, <BitsPerComponent, 1>, <ColorSpace, /DeviceGray>, <Filter, /CCITTFaxDecode>, <DecodeParms, <Columns, 2480>, <Rows, 3508>>, <Length, 241054>
97266a2b-5e2b-49e1-8b19-f6716f294a4d.jpg it appears that we don't support this file format.