PDFium,pdf中提取的图像已损坏,但渲染时没有问题

问题描述

我想提取 pdf 格式的图像,当我得到原始字节图像时,“找不到适合完成此操作的成像组件”损坏了图像。 我在文件中写入字节并使用 Windows 图像查看器和图像魔术进行测试,但仍然损坏。但任何pdf查看器都可以显示它。甚至我也可以使用 pdfium 从中获取渲染位图。

public byte[] GetimageRaw()
{
    var Meta = FPdfLib.Instance.PageImageObject_GetimageMetaData(handle,pageHandle);
    var size = Meta.width * Meta.height * Meta.bits_per_pixel / 8;
    return FPdfLib.Instance.PageImageObject_GetimageDataraw(handle,(int)size); // implemented down ?
}

public byte[] PageImageObject_GetimageDataraw(IntPtr pageImageObject,int bufferSize)
{
    lock (lockObj)
    {
        var buffer = new byte[bufferSize];
        var size = (int)FPdf.FPDFImageObj_GetimageDataraw(pageImageObject,buffer,(ulong)bufferSize); // implemented down ??
        var data = size == bufferSize ? buffer : buffer[..size];
        return data;
    }
}

// Get the raw image data of |image_object|. The raw data is the image data as
// stored in the PDF without applying any filters. |buffer| is only modified if
// |buflen| is longer than the length of the raw image data.
//
//   image_object - handle to an image object.
//   buffer       - buffer for holding the raw image data.
//   buflen       - length of the buffer in bytes.
//
// Returns the length of the raw image data.
[DllImport("pdfium.dll")]
public static extern ulong FPDFImageObj_GetimageDataraw(FPDF_PAGEOBJECT image_object,byte[] buffer,ulong buflen);

pdf 中的其他图像可以正常提取

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)